I have a wxPython application that contains a matplotlib panel (kindly provided by wxmpl, although I saw the same with a simple FigureCanvasWxAgg canvas).
I would like to revive one of the plots in the panel, and in the past I have done similar things. The way I do this is suggested:
- copy background
- plot
- [...]
- restore background
- update line data
- draw artist
- Blit
The problem is that the stories, instead of being “rewritten” by restoring the background, remain there, and all things, for obvious reasons, look messy.
Some (simplified) code:
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)
Then, when updating:
canvas.restore_region(bg_bottom)
line.set_ydata(new_y)
ax_bottom.draw_artist(line)
canvas.blit(ax_bottom.bbox)
A new line is drawn (and very fast! :), but for some reason this happens on the old line. Can anyone guess why?