我不明白使用 matplotlib 创建的图形是如何显示的,何时更新,何时阻塞等。
为了帮助我理解并帮助我让 matplotlib 做我特别需要的事情,谁能帮我创建一个 matplotlib.figure 包装器/几乎克隆,我们称之为 MyFigure,它的行为与下面的代码(及其注释)中描述的完全一样?
X=[0,1]
Y=[0,1]
Y2a=[0,2]
Y2b=[0,2.5]
Y3a=[0,3]
Y3b=[0,3.5]
Y4=[0,4]
fig = MyFigure() # Nothing happens
ax=fig.gca() # Nothing happens
ax.plot(X,Y) # Nothing happens
fig.show() # New window (1) appears and shows plot of X,Y; execution continues directly
ax.set_xlabel('X') # Window 1 gets X axis label
ax.set_ylabel('Y') # Window 1 gets Y axis label
fig.hide() # Window 1 disappears
time.sleep(10) # No open windows for 10 seconds
fig.show() # Window 1 reappears and looks the same as before
fig2 = MyFigure() # Nothing happens
fig2.show() # New window (2) appears and is empty
ax2 = fig2.gca() # Window 2 shows axes
ax2.plot(X,Y2a) # Window 2 shows X,Y2a
fig2.show() # Nothing happens, could be omitted
time.sleep(60) # Long computation. In the meantime, windows 1 and 2 can still be resized and their controls (zoom etc.) can be used
ax2.plot(X,Y2b) # Window 2 shows X,Y2a as well as X,Y2b
fig2.hide() # Window 2 disappears
fig3 = MyFigure() # Nothing happens
ax3 = fig3.gca() # Nothing happens
ax3.plot(X,Y3a) # Nothing happens
fig3.show() # Window 3 appears and shows plot of X,Y3a; execution continues
fig3.freeze() # Nothing happens, Window 3 is still open and can be manipulated
ax3.set_xlabel('X') # Nothing happens
ax3.set_ylabel('Y') # Nothing happens
fig3.thaw() # Window 3 gets X and Y axis labels
fig3.clear() # Window 3 is still open but empty
ax3 = fig3.gca() # Window 3 shows empty axes
ax3.plot(X,Y3b) # Window 3 shows plot of X,Y3b
一只萌萌小番薯
相关分类