@@ -184,17 +184,19 @@ def finish(self):
184184 'Finish any processing for writing the movie.'
185185 self .cleanup ()
186186
187- def grab_frame (self ):
187+ def grab_frame (self , ** savefig_kwargs ):
188188 '''
189189 Grab the image information from the figure and save as a movie frame.
190+ All keyword arguments in savefig_kwargs are passed on to the 'savefig'
191+ command that saves the figure.
190192 '''
191193 verbose .report ('MovieWriter.grab_frame: Grabbing frame.' ,
192194 level = 'debug' )
193195 try :
194196 # Tell the figure to save its data to the sink, using the
195197 # frame format and dpi.
196198 self .fig .savefig (self ._frame_sink (), format = self .frame_format ,
197- dpi = self .dpi )
199+ dpi = self .dpi , ** savefig_kwargs )
198200 except RuntimeError :
199201 out , err = self ._proc .communicate ()
200202 verbose .report ('MovieWriter -- Error running proc:\n %s\n %s' % (out ,
@@ -545,7 +547,8 @@ def _stop(self, *args):
545547 self .event_source = None
546548
547549 def save (self , filename , writer = None , fps = None , dpi = None , codec = None ,
548- bitrate = None , extra_args = None , metadata = None , extra_anim = None ):
550+ bitrate = None , extra_args = None , metadata = None , extra_anim = None ,
551+ savefig_kwargs = {}):
549552 '''
550553 Saves a movie file by drawing every frame.
551554
@@ -586,6 +589,11 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
586589 `matplotlib.Figure` instance. Also, animation frames will just be
587590 simply combined, so there should be a 1:1 correspondence between
588591 the frames from the different animations.
592+
593+ *savefig_kwargs* is a dictionary containing keyword arguments to be
594+ passed on to the 'savefig' command which is called repeatedly to save
595+ the individual frames. This can be used to set tight bounding boxes,
596+ for example.
589597 '''
590598 # Need to disconnect the first draw callback, since we'll be doing
591599 # draws. Otherwise, we'll end up starting the animation.
@@ -645,7 +653,7 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
645653 for anim , d in zip (all_anim , data ):
646654 #TODO: Need to see if turning off blit is really necessary
647655 anim ._draw_next_frame (d , blit = False )
648- writer .grab_frame ()
656+ writer .grab_frame (** savefig_kwargs )
649657
650658 # Reconnect signal for first draw if necessary
651659 if reconnect_first_draw :
0 commit comments