From 44f5bb4f58280bbb0498c3dc11ce9f583c182115 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 19 Mar 2020 20:38:53 +0100 Subject: [PATCH] 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. --- lib/matplotlib/animation.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 7ff2dd36b5bb..c9d7c03478a3 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -361,12 +361,10 @@ def finish(self): def grab_frame(self, **savefig_kwargs): # docstring inherited _log.debug('MovieWriter.grab_frame: Grabbing frame.') - # re-adjust the figure size in case it has been changed by the - # user. We must ensure that every frame is the same size or - # the movie will not save correctly. + # Readjust the figure size in case it has been changed by the user. + # All frames must have the same size to save the movie correctly. self.fig.set_size_inches(self._w, self._h) - # Tell the figure to save its data to the sink, using the - # frame format and dpi. + # Save the figure data to the sink, using the frame format and dpi. self.fig.savefig(self._frame_sink(), format=self.frame_format, dpi=self.dpi, **savefig_kwargs) @@ -1113,10 +1111,12 @@ def func(current_frame: int, total_frames: int) -> Any "frame size to vary, which is inappropriate for " "animation.") # canvas._is_saving = True makes the draw_event animation-starting - # callback a no-op. + # callback a no-op; canvas.manager = None prevents resizing the GUI + # widget (both are likewise done in savefig()). with mpl.rc_context({'savefig.bbox': None}), \ writer.saving(self._fig, filename, dpi), \ - cbook._setattr_cm(self._fig.canvas, _is_saving=True): + cbook._setattr_cm(self._fig.canvas, + _is_saving=True, manager=None): for anim in all_anim: anim._init_draw() # Clear the initial frame frame_number = 0