@@ -1826,12 +1826,19 @@ def set_active(self, active):
1826
1826
self .update_background (None )
1827
1827
1828
1828
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
+ """
1830
1833
axes = self .ax .get_figure ().get_axes ()
1831
1834
animated_artists = tuple ()
1832
1835
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 ))
1835
1842
return animated_artists
1836
1843
1837
1844
def update_background (self , event ):
@@ -1843,6 +1850,9 @@ def update_background(self, event):
1843
1850
# Make sure that widget artists don't get accidentally included in the
1844
1851
# background, by re-rendering the background if needed (and then
1845
1852
# 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
1846
1856
artists = self .artists + self ._get_animated_artists ()
1847
1857
needs_redraw = any (artist .get_visible () for artist in artists )
1848
1858
with ExitStack () as stack :
@@ -1899,9 +1909,10 @@ def update(self):
1899
1909
self .canvas .restore_region (self .background )
1900
1910
else :
1901
1911
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()
1902
1914
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 )
1905
1916
self .canvas .blit (self .ax .bbox )
1906
1917
else :
1907
1918
self .canvas .draw_idle ()
0 commit comments