3535# - Need comments, docstrings
3636# - Need to look at codecs
3737# - Is there a common way to add metadata?
38+ # - Should refactor the way we get frames to save to simplify saving from multiple figures
3839
3940# A registry for available MovieWriter classes
4041class MovieWriterRegistry (object ):
@@ -341,7 +342,7 @@ def _stop(self, *args):
341342 self .event_source = None
342343
343344 def save (self , filename , writer = None , fps = None , dpi = None , codec = None ,
344- bitrate = None ):
345+ bitrate = None , extra_anim = None ):
345346 '''
346347 Saves a movie file by drawing every frame.
347348
@@ -368,6 +369,12 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
368369 higher quality movie, but at the cost of increased file size. If no
369370 value is given, this defaults to the value given by the rcparam
370371 `animation.bitrate`.
372+
373+ *extra_anim* is a list of additional `Animation` objects that should
374+ be included in the saved movie file. These need to be from the same
375+ `matplotlib.Figure` instance. Also, animation frames will just be
376+ simply combined, so there should be a 1:1 correspondence between
377+ the frames from the different animations.
371378 '''
372379 # Need to disconnect the first draw callback, since we'll be doing
373380 # draws. Otherwise, we'll end up starting the animation.
@@ -396,6 +403,10 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
396403 if bitrate is None :
397404 bitrate = rcParams ['animation.bitrate' ]
398405
406+ all_anim = [self ]
407+ if not extra_anim is None :
408+ all_anim .extend (anim for anim in extra_anim if anim ._fig is self ._fig )
409+
399410 # If we have the name of a writer, instantiate an instance of the
400411 # registered class.
401412 if is_string_like (writer ):
@@ -414,9 +425,10 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
414425 # work since GUI widgets are gone. Either need to remove extra code
415426 # to allow for this non-existant use case or find a way to make it work.
416427 with writer .saving (self ._fig , filename , dpi ):
417- for data in self .new_saved_frame_seq ():
418- #TODO: Need to see if turning off blit is really necessary
419- self ._draw_next_frame (data , blit = False )
428+ for data in itertools .izip (* [a .new_saved_frame_seq () for a in all_anim ]):
429+ for anim ,d in zip (all_anim , data ):
430+ #TODO: Need to see if turning off blit is really necessary
431+ anim ._draw_next_frame (d , blit = False )
420432 writer .grab_frame ()
421433
422434 # Reconnect signal for first draw if necessary
0 commit comments