Here is a slightly modified version of your script which works for me.
I don't think this is the bug in mpl. Note that the ax.bbox does
change if the canvas size change. In your original script, the
copy_from_bbox is called before frame.Show() and this seems to cause a
mismatching bbox.
My modified example is also not perfect. A new background image needs
to be saved whenever ax.bbox changes (e.g. when resizing canvas).
-JJ
On Fri, May 8, 2009 at 5:02 PM, Elan Pavlov <epav...@gmail.com> wrote:
> Hi,
> Restore_region does not appear to work when embedding mpl into
> wxpython. Attached is a simple modification of the cookbook animation
> (http://www.scipy.org/Cookbook/Matplotlib/Animations) to illustrate
> this problem. I modified the example so it is updated on mouse
> movements (followed by idle time) so that the problem is more visual.
> There is also a flag to add one second timeouts between commands in
> the update method. When looking at the slowed animation it is clear
> that the background is never restored.
> Michiel Hoon thinks that the problem is due to the fact that
> restore_region is not implemented within the event loop and that the
> proper solution requires discussion:)
>
> Elan
> ---
> Of joys departed, not to return, how painful the remembrance.
> - Robert Blair
>
> ------------------------------------------------------------------------------
> The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
> production scanning environment may not be a perfect world - but thanks to
> Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
> Series Scanner you'll get full speed at 300 dpi even with all image
> processing features enabled. http://p.sf.net/sfu/kodak-com
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
>
#!/usr/bin/env python
import matplotlib
matplotlib.use('WXAgg')
import matplotlib.numerix as nx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
import wx
import time
# A flag to pause between every command in the update stage
slowdown=False
#--------------------------------------------------------------------------------------
class MainFrame(wx.Frame,matplotlib.figure.Figure):
"""Main frame for a simple graph."""
def __init__(self, parent, id):
wx.Frame.__init__(self,None,-1)
# creating the matplotlib figure and canvas.
self._fig = matplotlib.figure.Figure( None)
self.canvas = FigCanvas(self, wx.ID_ANY, self._fig )
# creating some data
self.x = nx.arange(0,2*nx.pi,0.01)
# adding the suplot and a line.
self.ax = self._fig.add_subplot(111)
self.line, = self.ax.plot(self.x, nx.sin(self.x), animated=True)
if slowdown==True:
time.sleep(1)
# Update when there is idle time. Note that this will only refire when
# something happens (such as a mouse movement) this will allow
# a better view of the dynamics of the updates.
self.Bind(wx.EVT_IDLE, self.update_line)
# a variable to induce change
self.update_line_cnt=0
return
def savebg(self):
# save the clean slate background -- everything but the animated line
# is drawn and saved in the pixel buffer background
self._fig.canvas.draw()
self.background = self._fig.canvas.copy_from_bbox(self.ax.bbox)
#--------------------------------------------------------------------------------------
def update_line(self,event):
""" This function will update and redraw the data"""
# update the data
self.line.set_ydata(nx.sin(self.x+self.update_line_cnt/20.0))
# restore the clean slate background
self._fig.canvas.restore_region(self.background)
if slowdown==True:
time.sleep(1)
# just draw the animated artist
self.ax.draw_artist(self.line)
if slowdown==True:
time.sleep(1)
# just redraw the axes rectangle
self._fig.canvas.blit(self.ax.bbox)
if slowdown==True:
time.sleep(1)
# Uncomment to speed up updates without actions.
#event.RequestMore(True)
#Getting some changes
self.update_line_cnt+=1
return True
#--------------------------------------------------------------------------------------
if __name__ == '__main__':
App=wx.App()
frame=MainFrame(None,-1)
frame.Show(True)
frame.savebg()
App.MainLoop()
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel