From d405b1cc98f5bcb580489a268f02bec14418eba3 Mon Sep 17 00:00:00 2001 From: Oliver Natt Date: Fri, 22 Feb 2019 14:07:16 +0100 Subject: [PATCH 1/2] Fix for issue #13478: In an animation using blitting that contains some static graphics elements, the static parts of the figure are not updated after an interactive zoom/pan event. However, they are correctly updated after an resize event. --- lib/matplotlib/animation.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index f6376ed9c051..a0c22ded11cb 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1222,6 +1222,14 @@ def _setup_blit(self): # axes self._blit_cache = dict() self._drawn_artists = [] + def remove_from_cache(ax): + try: + del self._blit_cache[ax] + except KeyError: + pass + for ax in self._fig.axes: + ax.callbacks.connect('xlim_changed', remove_from_cache) + ax.callbacks.connect('ylim_changed', remove_from_cache) self._resize_id = self._fig.canvas.mpl_connect('resize_event', self._handle_resize) self._post_draw(None, self._blit) From 03d41e891a569bd0afd9253ddefc765549e19edc Mon Sep 17 00:00:00 2001 From: Oliver Natt Date: Sat, 23 Feb 2019 11:19:40 +0100 Subject: [PATCH 2/2] Made the code more concise by avoiding try-catch and using lambda. --- lib/matplotlib/animation.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index a0c22ded11cb..4cdd42469f88 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1222,14 +1222,11 @@ def _setup_blit(self): # axes self._blit_cache = dict() self._drawn_artists = [] - def remove_from_cache(ax): - try: - del self._blit_cache[ax] - except KeyError: - pass for ax in self._fig.axes: - ax.callbacks.connect('xlim_changed', remove_from_cache) - ax.callbacks.connect('ylim_changed', remove_from_cache) + ax.callbacks.connect('xlim_changed', + lambda ax: self._blit_cache.pop(ax, None)) + ax.callbacks.connect('ylim_changed', + lambda ax: self._blit_cache.pop(ax, None)) self._resize_id = self._fig.canvas.mpl_connect('resize_event', self._handle_resize) self._post_draw(None, self._blit)