Skip to content

Commit e6c4a67

Browse files
committed
MNT: move logic from Animation.save to AbstractMovieWriter.saving
This makes the validation that the rcparams are not going to mess with frame size more generally available without duplicating it.
1 parent 63e2614 commit e6c4a67

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/matplotlib/animation.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,18 @@ def saving(self, fig, outfile, dpi, *args, **kwargs):
233233
234234
``*args, **kw`` are any parameters that should be passed to `setup`.
235235
"""
236+
if mpl.rcParams['savefig.bbox'] == 'tight':
237+
_log.info("Disabling savefig.bbox = 'tight', as it may cause "
238+
"frame size to vary, which is inappropriate for "
239+
"animation.")
240+
236241
# This particular sequence is what contextlib.contextmanager wants
237242
self.setup(fig, outfile, dpi, *args, **kwargs)
238-
try:
239-
yield self
240-
finally:
241-
self.finish()
243+
with mpl.rc_context({'savefig.bbox': None}):
244+
try:
245+
yield self
246+
finally:
247+
self.finish()
242248

243249

244250
class MovieWriter(AbstractMovieWriter):
@@ -1061,10 +1067,6 @@ def func(current_frame: int, total_frames: int) -> Any
10611067
# TODO: Right now, after closing the figure, saving a movie won't work
10621068
# since GUI widgets are gone. Either need to remove extra code to
10631069
# allow for this non-existent use case or find a way to make it work.
1064-
if mpl.rcParams['savefig.bbox'] == 'tight':
1065-
_log.info("Disabling savefig.bbox = 'tight', as it may cause "
1066-
"frame size to vary, which is inappropriate for "
1067-
"animation.")
10681070

10691071
facecolor = savefig_kwargs.get('facecolor',
10701072
mpl.rcParams['savefig.facecolor'])
@@ -1080,10 +1082,8 @@ def _pre_composite_to_white(color):
10801082
# canvas._is_saving = True makes the draw_event animation-starting
10811083
# callback a no-op; canvas.manager = None prevents resizing the GUI
10821084
# widget (both are likewise done in savefig()).
1083-
with mpl.rc_context({'savefig.bbox': None}), \
1084-
writer.saving(self._fig, filename, dpi), \
1085-
cbook._setattr_cm(self._fig.canvas,
1086-
_is_saving=True, manager=None):
1085+
with writer.saving(self._fig, filename, dpi), \
1086+
cbook._setattr_cm(self._fig.canvas, _is_saving=True, manager=None):
10871087
for anim in all_anim:
10881088
anim._init_draw() # Clear the initial frame
10891089
frame_number = 0

0 commit comments

Comments
 (0)