Revision: 8665 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8665&view=rev Author: ryanmay Date: 2010-08-27 18:13:22 +0000 (Fri, 27 Aug 2010)
Log Message: ----------- Fix some issues with saving movies from FuncAnimation. The initialization draw was putting data in the saved sequence, which needed to be removed. Also, handle the case where there is no saved sequence. Make sure to disconnect signals for first draw, otherwise saving the movie will start the animation. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/animation.py Modified: trunk/matplotlib/lib/matplotlib/animation.py =================================================================== --- trunk/matplotlib/lib/matplotlib/animation.py 2010-08-27 07:13:14 UTC (rev 8664) +++ trunk/matplotlib/lib/matplotlib/animation.py 2010-08-27 18:13:22 UTC (rev 8665) @@ -26,6 +26,7 @@ return ret return wrapper +import itertools from matplotlib.cbook import iterable class Animation(object): @@ -78,6 +79,7 @@ self.event_source.add_callback(self._step) self.event_source.start() self._fig.canvas.mpl_disconnect(self._first_draw_id) + self._first_draw_id = None # So we can check on save def _stop(self, *args): # On stop we disconnect all of our events. @@ -103,6 +105,14 @@ image files. This prefix will have a frame number (i.e. 0001) appended when saving individual frames. ''' + # Need to disconnect the first draw callback, since we'll be doing + # draws. Otherwise, we'll end up starting the animation. + if self._first_draw_id is not None: + self._fig.canvas.mpl_disconnect(self._first_draw_id) + reconnect_first_draw = True + else: + reconnect_first_draw = False + fnames = [] # Create a new sequence of frames for saved data. This is different # from new_frame_seq() to give the ability to save 'live' generated @@ -121,6 +131,11 @@ for fname in fnames: os.remove(fname) + # Reconnect signal for first draw if necessary + if reconnect_first_draw: + self._first_draw_id = self._fig.canvas.mpl_connect('draw_event', + self._start) + def ffmpeg_cmd(self, fname, fps, codec, frame_prefix): # Returns the command line parameters for subprocess to use # ffmpeg to create a movie @@ -401,7 +416,6 @@ # be a generator. An iterable will be used as is, and anything else # will be treated as a number of frames. if frames is None: - import itertools self._iter_gen = itertools.count elif callable(frames): self._iter_gen = frames @@ -417,17 +431,28 @@ self.save_count = 100 self._init_func = init_func - self._save_seq = [] + # Needs to be initialized so the draw functions work without checking + self._save_seq = [] + TimedAnimation.__init__(self, fig, **kwargs) + # Need to reset the saved seq, since right now it will contain data + # for a single frame from init, which is not what we want. + self._save_seq = [] + def new_frame_seq(self): # Use the generating function to generate a new frame sequence return self._iter_gen() def new_saved_frame_seq(self): - # Generate an iterator for the sequence of saved data. - return iter(self._save_seq) + # Generate an iterator for the sequence of saved data. If there are + # no saved frames, generate a new frame sequence and take the first + # save_count entries in it. + if self._save_seq: + return iter(self._save_seq) + else: + return itertools.islice(self.new_frame_seq(), self.save_count) def _init_draw(self): # Initialize the drawing either using the given init_func or by This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Sell apps to millions through the Intel(R) Atom(Tm) Developer Program Be part of this innovative community and reach millions of netbook users worldwide. Take advantage of special opportunities to increase revenue and speed time-to-market. Join now, and jumpstart your future. http://p.sf.net/sfu/intel-atom-d2d _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins