@@ -1839,6 +1839,15 @@ def set_active(self, active):
18391839 if active :
18401840 self .update_background (None )
18411841
1842+ def _get_animated_artists (self ):
1843+ """Convenience method to get all animated artists of a figure."""
1844+ axes = self .ax .get_figure ().get_axes ()
1845+ animated_artists = tuple ()
1846+ for ax in axes :
1847+ artists = sorted (ax .get_children (), key = lambda x : x .zorder )
1848+ animated_artists += tuple (a for a in artists if a .get_animated ())
1849+ return animated_artists
1850+
18421851 def update_background (self , event ):
18431852 """Force an update of the background."""
18441853 # If you add a call to `ignore` here, you'll want to check edge case:
@@ -1848,15 +1857,16 @@ def update_background(self, event):
18481857 # Make sure that widget artists don't get accidentally included in the
18491858 # background, by re-rendering the background if needed (and then
18501859 # re-re-rendering the canvas with the visible widget artists).
1851- needs_redraw = any (artist .get_visible () for artist in self .artists )
1860+ artists = self .artists + self ._get_animated_artists ()
1861+ needs_redraw = any (artist .get_visible () for artist in artists )
18521862 with ExitStack () as stack :
18531863 if needs_redraw :
1854- for artist in self . artists :
1864+ for artist in artists :
18551865 stack .enter_context (artist ._cm_set (visible = False ))
18561866 self .canvas .draw ()
18571867 self .background = self .canvas .copy_from_bbox (self .ax .bbox )
18581868 if needs_redraw :
1859- for artist in self . artists :
1869+ for artist in artists :
18601870 self .ax .draw_artist (artist )
18611871
18621872 def connect_default_events (self ):
@@ -1903,8 +1913,9 @@ def update(self):
19031913 self .canvas .restore_region (self .background )
19041914 else :
19051915 self .update_background (None )
1906- for artist in self .artists :
1907- self .ax .draw_artist (artist )
1916+ for artist in self .artists + self ._get_animated_artists ():
1917+ if artist .stale :
1918+ self .ax .draw_artist (artist )
19081919 self .canvas .blit (self .ax .bbox )
19091920 else :
19101921 self .canvas .draw_idle ()
0 commit comments