import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
def call_back(event):
axtemp=event.inaxes
x_min, x_max = axtemp.get_xlim()
fanwei = (x_max - x_min) / 10
if event.button == 'up':
axtemp.set(xlim=(x_min + fanwei, x_max - fanwei))
print('up')
elif event.button == 'down':
axtemp.set(xlim=(x_min - fanwei, x_max + fanwei))
print('down')
fig.canvas.draw_idle() # 绘图动作实时反映在图像上
fig.canvas.mpl_connect('scroll_event', call_back)
fig.canvas.mpl_connect('button_press_event', call_back)
ax1 = plt.subplot(3,1,1)#截取幕布的一部分
ax1.xaxis.set_major_formatter(plt.NullFormatter()) # 取消x轴坐标
x = np.linspace(-5, 5, 10)
y = x ** 2 + 1
plt.ylabel('first')
plt.plot(x, y)
plt.grid()
ax2 = plt.subplot(3,1,2)
ax2.xaxis.set_major_formatter(plt.NullFormatter()) # 取消x轴坐标
y1=-x**2+1
plt.plot(x, y1)
ax3 = plt.subplot(3,1,3)
y3=-x*2+1
plt.plot(x, y3)
plt.show()

PS:在相应坐标系内滚动鼠标滚轮即可放大/缩小x轴。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理