@@ -233,12 +233,18 @@ def saving(self, fig, outfile, dpi, *args, **kwargs):
233
233
234
234
``*args, **kw`` are any parameters that should be passed to `setup`.
235
235
"""
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
+
236
241
# This particular sequence is what contextlib.contextmanager wants
237
242
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 ()
242
248
243
249
244
250
class MovieWriter (AbstractMovieWriter ):
@@ -1061,10 +1067,6 @@ def func(current_frame: int, total_frames: int) -> Any
1061
1067
# TODO: Right now, after closing the figure, saving a movie won't work
1062
1068
# since GUI widgets are gone. Either need to remove extra code to
1063
1069
# 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." )
1068
1070
1069
1071
facecolor = savefig_kwargs .get ('facecolor' ,
1070
1072
mpl .rcParams ['savefig.facecolor' ])
@@ -1080,10 +1082,8 @@ def _pre_composite_to_white(color):
1080
1082
# canvas._is_saving = True makes the draw_event animation-starting
1081
1083
# callback a no-op; canvas.manager = None prevents resizing the GUI
1082
1084
# 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 ):
1087
1087
for anim in all_anim :
1088
1088
anim ._init_draw () # Clear the initial frame
1089
1089
frame_number = 0
0 commit comments