根据文档 https://matplotlib.org/3.2.2/users/navigation_toolbar.html#interactive-navigation, the Forward
and Back
按钮用于让您返回到单个图形的先前视图。例如,如果您使用 Zoom-to-rectangle
特征,即Back
按钮将使您返回到之前的显示。根据您的后端,按下这些按钮时可能会挂起。
显然,您可以使用同时绘制多个图表subplot
如下:
import scipy
from matplotlib import pyplot
DataRange = range(0, 360)
DataRange = map(scipy.deg2rad, DataRange)
Data1 = map(scipy.sin, DataRange)
Data2 = map(scipy.cos, DataRange)
pyplot.subplot(211)
pyplot.plot(Data1)
pyplot.subplot(212)
pyplot.plot(Data2)
pyplot.show()
给你:
或者,您可以在单击两个图形时使用以下命令在它们之间交替:
import scipy
from matplotlib import pyplot
DataRange = range(0, 360)
DataRange = map(scipy.deg2rad, DataRange)
Data1 = map(scipy.sin, DataRange)
Data2 = map(scipy.cos, DataRange)
toggle = True
def onclick(event):
global toggle
toggle = not toggle
event.canvas.figure.clear()
if toggle:
event.canvas.figure.gca().plot(Data1)
else:
event.canvas.figure.gca().plot(Data2)
event.canvas.draw()
fig = pyplot.figure()
fig.canvas.mpl_connect('button_press_event', onclick)
pyplot.plot(Data1)
pyplot.show()