From 97c47b4049212b523a933b7ef440e2fa4ffe43bd Mon Sep 17 00:00:00 2001 From: fredrik-1 Date: Thu, 16 Aug 2018 10:20:52 +0200 Subject: [PATCH] making it possible to use writer.setup kwargs from animation.save --- lib/matplotlib/animation.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 9dd3f68f0a8c..6c136dc89ed6 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -218,7 +218,7 @@ def finish(self): '''Finish any processing for writing the movie.''' @contextlib.contextmanager - def saving(self, fig, outfile, dpi, *args, **kwargs): + def saving(self, fig, outfile, dpi=None, *args, **kwargs): ''' Context manager to facilitate writing the movie file. @@ -847,7 +847,7 @@ def __init__(self, fps=30, codec=None, bitrate=None, extra_args=None, self._hit_limit = False super().__init__(fps, codec, bitrate, extra_args, metadata) - def setup(self, fig, outfile, dpi, frame_dir=None): + def setup(self, fig, outfile, dpi=None, frame_dir=None): root, ext = os.path.splitext(outfile) if ext not in ['.html', '.htm']: raise ValueError("outfile must be *.htm or *.html") @@ -861,7 +861,8 @@ def setup(self, fig, outfile, dpi, frame_dir=None): else: frame_prefix = None - super().setup(fig, outfile, dpi, frame_prefix, clear_temp=False) + super().setup(fig, outfile, dpi=None, frame_prefix=frame_prefix, + clear_temp=False) def grab_frame(self, **savefig_kwargs): if self.embed_frames: @@ -1005,7 +1006,7 @@ def _stop(self, *args): def save(self, filename, writer=None, fps=None, dpi=None, codec=None, bitrate=None, extra_args=None, metadata=None, extra_anim=None, - savefig_kwargs=None): + savefig_kwargs=None, **kwargs): '''Saves a movie file by drawing every frame. Parameters @@ -1060,6 +1061,9 @@ class to use, such as 'ffmpeg'. If ``None``, defaults to on to the `savefig` command which is called repeatedly to save the individual frames. + **kwargs : + Additional kwargs passed to writer.setup(). + Notes ----- fps, codec, bitrate, extra_args, metadata are used to @@ -1155,7 +1159,7 @@ class to use, such as 'ffmpeg'. If ``None``, defaults to "frame size to vary, which is inappropriate for " "animation.") rcParams['savefig.bbox'] = None - with writer.saving(self._fig, filename, dpi): + with writer.saving(self._fig, filename, dpi, **kwargs): for anim in all_anim: # Clear the initial frame anim._init_draw()