@@ -1842,15 +1842,11 @@ def set_active(self, active):
18421842 def _get_animated_artists (self ):
18431843 """
18441844 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.
18461846 """
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 ])
18541850
18551851 def update_background (self , event ):
18561852 """Force an update of the background."""
@@ -1864,7 +1860,9 @@ def update_background(self, event):
18641860 # We need to remove all artists which will be drawn when updating
18651861 # the selector: if we have animated artists in the figure, it is safer
18661862 # 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 ())
18681866 needs_redraw = any (artist .get_visible () for artist in artists )
18691867 with ExitStack () as stack :
18701868 if needs_redraw :
@@ -1921,8 +1919,11 @@ def update(self):
19211919 else :
19221920 self .update_background (None )
19231921 # 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 :
19261927 self .ax .draw_artist (artist )
19271928 self .canvas .blit (self .ax .bbox )
19281929 else :
0 commit comments