After searching through the forums and trying many different things I have been unable to get animation working correctly using matplotlib in my python application. I'm hoping one of the experts here can take a quick look at my code and tell me what I am doing incorrectly.
What I am seeing is that the each line continues to be drawn as part of my [timer] update call. I suspect that it is related to the 'hold' call but changing the hold state had no effect. I've tried numerous different scenarios based on available examples but so far nothing has seemed to help. Here is the code: import matplotlib as mpl mpl.use('WXAgg') mpl.rcParams['toolbar'] = 'None' import wx from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas from matplotlib.figure import Figure import numpy as num # begin wxGlade: dependencies # end wxGlade # begin wxGlade: extracode # end wxGlade class HeartPanel(wx.Panel): def __init__(self, *args, **kwds): # begin wxGlade: HeartPanel.__init__ kwds["style"] = wx.RAISED_BORDER|wx.TAB_TRAVERSAL wx.Panel.__init__(self, *args, **kwds) self.__set_properties() self.__do_layout() # end wxGlade mpl.rc('figure', fc='black', dpi=96, ec='black') self.figure = Figure(figsize=(5.2, 1.25)) self.canvas = Canvas(self, -1, self.figure) self.canvas.SetBackgroundColour(wx.Colour(0, 0, 0)) # self.canvas.draw() self.bgnd = None self.timer = wx.Timer(self, 5555) self.Bind(wx.EVT_TIMER, self.on_timer, self.timer) self.count = 0 def __set_properties(self): # begin wxGlade: HeartPanel.__set_properties self.SetMinSize((500,120)) self.SetBackgroundColour(wx.Colour(0, 0, 0)) self.SetForegroundColour(wx.Colour(0, 255, 0)) # end wxGlade def __do_layout(self): # begin wxGlade: HeartPanel.__do_layout pass # end wxGlade # pylint: disable-msg=W0201 def init_plot(self): ''' Method to initialize the plot that is used to animate the display. ''' self.figure.subplots_adjust(left=0, top=1, right=1, bottom=0) self.axes = self.figure.add_subplot(111) if self.bgnd == None: self.bgnd = self.canvas.copy_from_bbox(self.axes.bbox) self.axes.set_axis_bgcolor('black') self.x_data = num.arange(0, 2*num.pi, 0.01) self.line = self.axes.plot(self.x_data, \ num.sin(self.x_data), \ color='green', \ figure=self.figure, \ lw=2, \ animated=True) self.axes.hold(False) def start_timer(self, time_value=100): ''' Method to start the animation update timer. ''' # self.axes.draw() self.canvas.Show(True) # self.canvas.draw() self.count = 0 self.timer.Start(time_value, wx.TIMER_CONTINUOUS) def stop_timer(self): ''' Method to stop the animation update timer. ''' self.canvas.Show(False) self.timer.Stop() def on_timer(self, event): ''' Event handler for the animation update timer. ''' self.count += 1 self.canvas.restore_region(self.bgnd) # update the data self.line[0].set_ydata(num.sin(self.x_data + self.count/10.0)) self.axes.clear() # just draw the animated artist self.axes.draw_artist(self.line[0]) # just redraw the axes rectangle self.canvas.blit(self.axes.bbox) # end of class HeartPanel Any help is greatly appreciated. -- View this message in context: http://www.nabble.com/python-and-matplotlib-animation-tp21185506p21185506.html Sent from the matplotlib - users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users