Hi,
I can't get wxpython to play well with matplotlib and draw_artist.
After mucking around quite a bit I think I narrowed it down to the
draw_artist function The problem seems to be that draw_artist when
working within wxpython (as opposed to a simple mpl window) doesn't
remove the old points it plotted. I adapted the example from the
cookbook (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.
Replacing the copy_from_bbox/restore/draw_artist (i.e. removing the
animated properties) with the simple draw causes this to work. The
copy_from_bbox/restore methods work as expected so it seems that the
problem is either the draw_artist (or possibly the blit, but that
seems unlikely).
Is there something I am doing wrong?
Elan
--
Beware of bugs in the above code; I have only proved it correct, not tried it.
- Donald Knuth
#!/usr/bin/env python
import matplotlib.numerix as nx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
import wx
#--------------------------------------------------------------------------------------
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)
# save the clean slate background -- everything but the animated line
# is drawn and saved in the pixel buffer background
self.background = self._fig.canvas.copy_from_bbox(self.ax.bbox)
# 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 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)
# just draw the animated artist
self.ax.draw_artist(self.line)
# just redraw the axes rectangle
self._fig.canvas.blit(self.ax.bbox)
#Getting some changes
self.update_line_cnt+=1
return True
#--------------------------------------------------------------------------------------
if __name__ == '__main__':
App=wx.App()
frame=MainFrame(None,-1)
frame.Show(True)
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-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users