Skip to content

Commit 44f5bb4

Browse files
committed
Disconnect manager when resizing figure for animation saving.
This is similar to what's done in savefig() to prevent the GUI window from being resized, and is also helpful as this code may trigger after the GUI window has been closed.
1 parent bb7f9b9 commit 44f5bb4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/matplotlib/animation.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,10 @@ def finish(self):
361361
def grab_frame(self, **savefig_kwargs):
362362
# docstring inherited
363363
_log.debug('MovieWriter.grab_frame: Grabbing frame.')
364-
# re-adjust the figure size in case it has been changed by the
365-
# user. We must ensure that every frame is the same size or
366-
# the movie will not save correctly.
364+
# Readjust the figure size in case it has been changed by the user.
365+
# All frames must have the same size to save the movie correctly.
367366
self.fig.set_size_inches(self._w, self._h)
368-
# Tell the figure to save its data to the sink, using the
369-
# frame format and dpi.
367+
# Save the figure data to the sink, using the frame format and dpi.
370368
self.fig.savefig(self._frame_sink(), format=self.frame_format,
371369
dpi=self.dpi, **savefig_kwargs)
372370

@@ -1113,10 +1111,12 @@ def func(current_frame: int, total_frames: int) -> Any
11131111
"frame size to vary, which is inappropriate for "
11141112
"animation.")
11151113
# canvas._is_saving = True makes the draw_event animation-starting
1116-
# callback a no-op.
1114+
# callback a no-op; canvas.manager = None prevents resizing the GUI
1115+
# widget (both are likewise done in savefig()).
11171116
with mpl.rc_context({'savefig.bbox': None}), \
11181117
writer.saving(self._fig, filename, dpi), \
1119-
cbook._setattr_cm(self._fig.canvas, _is_saving=True):
1118+
cbook._setattr_cm(self._fig.canvas,
1119+
_is_saving=True, manager=None):
11201120
for anim in all_anim:
11211121
anim._init_draw() # Clear the initial frame
11221122
frame_number = 0

0 commit comments

Comments
 (0)