Skip to content

Commit 29dad01

Browse files
committed
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.
1 parent b3f61d1 commit 29dad01

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/matplotlib/animation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,16 @@ def _setup_blit(self):
11991199
# axes
12001200
self._blit_cache = dict()
12011201
self._drawn_artists = []
1202+
# _post_draw needs to be called first to initialize the renderer
1203+
self._post_draw(None, self._blit)
1204+
# Then we need to clear the Frame for the initial draw
1205+
# This is typically handled in _on_resize because QT and Tk
1206+
# emit a resize event on launch, but the macosx backend does not,
1207+
# thus we force it here for everyone for consistency
1208+
self._init_draw()
1209+
# Connect to future resize events
12021210
self._resize_id = self._fig.canvas.mpl_connect('resize_event',
12031211
self._on_resize)
1204-
self._post_draw(None, self._blit)
12051212

12061213
def _on_resize(self, event):
12071214
# On resize, we need to disable the resize event handling so we don't

src/_macosx.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,8 @@ - (void)updateDevicePixelRatio:(double)scale
13291329
goto exit;
13301330
}
13311331
if (PyObject_IsTrue(change)) {
1332+
// Notify that there was a resize_event that took place
1333+
gil_call_method(canvas, "resize_event");
13321334
[self setNeedsDisplay: YES];
13331335
}
13341336

0 commit comments

Comments
 (0)