我有一个wxPython应用程序,它包含一个matplotlib面板(由wxmpl提供,尽管我在普通的FigureCanvasWxAgg画布上也看到了同样的情况)。
我想在面板中给其中一个情节动画,而在过去,我也做过类似的事情。我的做法是建议:
复制background
问题是,这些情节,而不是被背景恢复“覆盖”,留在那里,这是可以理解的,看起来一团糟。
一些(简化的)代码:
fig = self.myPanel.get_figure()
ax_top = fig.add_subplot(211)
ax_bottom = self.fig.add_subplot(212)
canvas = fig.canvas
canvas.draw()
bg_top = canvas.copy_from_bbox(ax_top.bbox)
bg_bottom = canvas.copy_from_bbox(ax_bottom.bbox)
line, = ax_bottom.plot(x, y, 'k', animated=True)然后,在更新时:
canvas.restore_region(bg_bottom)
line.set_ydata(new_y)
ax_bottom.draw_artist(line)
canvas.blit(ax_bottom.bbox)新的线会被绘制出来(非常快!:),但是由于某种原因,它会发生在旧的线上。有人能猜到为什么吗?
发布于 2011-06-11 05:54:52
作为答复,应请求增加:)
在调用fig.canvas.draw()之前尝试调用fig.canvas.copy_from_bbox。确切的行为取决于后端,因此它在不同的平台上会有所不同,但是一般来说,在尝试从它复制东西之前,您需要先画出画布。
发布于 2011-06-22 23:32:14
用FigureCanvasWxAgg测试。我认为,在初始化面板和轴之间,然后绘制轴时,会移动或调整轴的大小。试着等待获得这些背景,直到实际绘图,即初始化框架/面板时:
...
bg_top = None
bg_bottom = None
line, = ax_bottom.plot(x, y, 'k', animated=True)
...更新时:
def update(self, evt):
if bf_top is None:
bg_top = canvas.copy_from_bbox(ax_top.bbox)
bg_bottom = canvas.copy_from_bbox(ax_bottom.bbox)
canvas.restore_region(bg_bottom)
line.set_ydata(new_y)
ax_bottom.draw_artist(line)
canvas.blit(ax_bottom.bbox)发布于 2013-08-27 05:17:26
您必须将“draw_event”链接到新的背景副本。否则,旧的背景总是会在你想要的背景上,你只能在工具栏中使用缩放或平移。对我来说很管用。
马丁。
https://stackoverflow.com/questions/6286731
复制相似问题