@@ -1842,15 +1842,11 @@ def set_active(self, active):
1842
1842
def _get_animated_artists (self ):
1843
1843
"""
1844
1844
Convenience method to get all animated artists of a figure, except
1845
- those already present in self.artists.
1845
+ those already present in self.artists. 'z_order' is ignored.
1846
1846
"""
1847
- animated_artists = []
1848
- for ax in self .ax .get_figure ().get_axes ():
1849
- # Make sure we don't get the artists already in self.artists
1850
- l = [a for a in ax .get_children ()
1851
- if (a .get_animated () and a not in self .artists )]
1852
- animated_artists .extend (sorted (l , key = lambda a : a .zorder ))
1853
- return tuple (animated_artists )
1847
+ return tuple ([a for ax_ in self .ax .get_figure ().get_axes ()
1848
+ for a in ax_ .get_children ()
1849
+ if a .get_animated () and a not in self .artists ])
1854
1850
1855
1851
def update_background (self , event ):
1856
1852
"""Force an update of the background."""
@@ -1864,7 +1860,9 @@ def update_background(self, event):
1864
1860
# We need to remove all artists which will be drawn when updating
1865
1861
# the selector: if we have animated artists in the figure, it is safer
1866
1862
# to redrawn by default, in case they have updated by the callback
1867
- artists = self .artists + self ._get_animated_artists ()
1863
+ # zorder needs to be respected when redrawing
1864
+ artists = sorted (self .artists + self ._get_animated_artists (),
1865
+ key = lambda a : a .get_zorder ())
1868
1866
needs_redraw = any (artist .get_visible () for artist in artists )
1869
1867
with ExitStack () as stack :
1870
1868
if needs_redraw :
@@ -1921,8 +1919,11 @@ def update(self):
1921
1919
else :
1922
1920
self .update_background (None )
1923
1921
# We need to draw all artists, which are not included in the
1924
- # background, therefore we add self._get_animated_artists()
1925
- for artist in self .artists + self ._get_animated_artists ():
1922
+ # background, therefore we also draw self._get_animated_artists()
1923
+ # and we make sure that we respect z_order
1924
+ artists = sorted (self .artists + self ._get_animated_artists (),
1925
+ key = lambda a : a .get_zorder ())
1926
+ for artist in artists :
1926
1927
self .ax .draw_artist (artist )
1927
1928
self .canvas .blit (self .ax .bbox )
1928
1929
else :
0 commit comments