Skip to content

Commit 515aa53

Browse files
committed
Fix getting tuple of animated artists and add comments
1 parent 28d4325 commit 515aa53

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/matplotlib/widgets.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,12 +1826,19 @@ def set_active(self, active):
18261826
self.update_background(None)
18271827

18281828
def _get_animated_artists(self):
1829-
"""Convenience method to get all animated artists of a figure."""
1829+
"""
1830+
Convenience method to get all animated artists of a figure, except
1831+
those already present in self.artists.
1832+
"""
18301833
axes = self.ax.get_figure().get_axes()
18311834
animated_artists = tuple()
18321835
for ax in axes:
1833-
artists = sorted(ax.get_children(), key=lambda x: x.zorder)
1834-
animated_artists += tuple(a for a in artists if a.get_animated())
1836+
# Make sure we don't get the artists already in self.artists
1837+
artists = filter(
1838+
lambda x: x.get_animated() and x not in self.artists,
1839+
ax.get_children()
1840+
)
1841+
animated_artists += tuple(sorted(artists, key=lambda x: x.zorder))
18351842
return animated_artists
18361843

18371844
def update_background(self, event):
@@ -1843,6 +1850,9 @@ def update_background(self, event):
18431850
# Make sure that widget artists don't get accidentally included in the
18441851
# background, by re-rendering the background if needed (and then
18451852
# re-re-rendering the canvas with the visible widget artists).
1853+
# We need to remove all artists which will be drawn when updating
1854+
# the selector: if we have animated artists in the figure, it is safer
1855+
# to redrawn by default, in case they have updated by the callback
18461856
artists = self.artists + self._get_animated_artists()
18471857
needs_redraw = any(artist.get_visible() for artist in artists)
18481858
with ExitStack() as stack:
@@ -1899,9 +1909,10 @@ def update(self):
18991909
self.canvas.restore_region(self.background)
19001910
else:
19011911
self.update_background(None)
1912+
# We need to draw all artists, which are not included in the
1913+
# background, therefore we add self._get_animated_artists()
19021914
for artist in self.artists + self._get_animated_artists():
1903-
if artist.stale:
1904-
self.ax.draw_artist(artist)
1915+
self.ax.draw_artist(artist)
19051916
self.canvas.blit(self.ax.bbox)
19061917
else:
19071918
self.canvas.draw_idle()

0 commit comments

Comments
 (0)