From 29dad01aa6ecbedbf1a59a938527cd5f9d3ac2e5 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Sun, 9 Jan 2022 14:27:00 -0700 Subject: [PATCH] FIX: Update macosx animation handling - Emit a resize_event signal when the pixel ratio is updated. This enables an animation to move between hidpi and standard dpi screens without ruining the blitting. - Init the draw in the animation. This is only necessary for macosx because an initial resize isn't emitted upon figure manager creation, versus the other backends where it is. This would cause the first frame to be stale on the macosx animations when used with blitting. --- lib/matplotlib/animation.py | 9 ++++++++- src/_macosx.m | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 7909d11352b7..9b9cb910c01e 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1199,9 +1199,16 @@ def _setup_blit(self): # axes self._blit_cache = dict() self._drawn_artists = [] + # _post_draw needs to be called first to initialize the renderer + self._post_draw(None, self._blit) + # Then we need to clear the Frame for the initial draw + # This is typically handled in _on_resize because QT and Tk + # emit a resize event on launch, but the macosx backend does not, + # thus we force it here for everyone for consistency + self._init_draw() + # Connect to future resize events self._resize_id = self._fig.canvas.mpl_connect('resize_event', self._on_resize) - self._post_draw(None, self._blit) def _on_resize(self, event): # On resize, we need to disable the resize event handling so we don't diff --git a/src/_macosx.m b/src/_macosx.m index 2beeda14722d..4fc6322bf0a2 100755 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -1329,6 +1329,8 @@ - (void)updateDevicePixelRatio:(double)scale goto exit; } if (PyObject_IsTrue(change)) { + // Notify that there was a resize_event that took place + gil_call_method(canvas, "resize_event"); [self setNeedsDisplay: YES]; }