2828import sys
2929from tempfile import TemporaryDirectory
3030import uuid
31+ import warnings
3132
3233import numpy as np
3334
@@ -907,6 +908,8 @@ class Animation:
907908 """
908909
909910 def __init__ (self , fig , event_source = None , blit = False ):
911+ self ._draw_was_started = False
912+
910913 self ._fig = fig
911914 # Disables blitting for backends that don't support it. This
912915 # allows users to request it if available, but still have a
@@ -931,6 +934,14 @@ def __init__(self, fig, event_source=None, blit=False):
931934 if self ._blit :
932935 self ._setup_blit ()
933936
937+ def __del__ (self ):
938+ if not getattr (self , '_draw_was_started' , True ):
939+ warnings .warn (
940+ 'Animation was deleted without rendering anything. This is '
941+ 'most likely unintended. To prevent deletion, assign the '
942+ 'Animation to a variable that exists for as long as you need '
943+ 'the Animation.' )
944+
934945 def _start (self , * args ):
935946 """
936947 Starts interactive animation. Adds the draw frame command to the GUI
@@ -1166,7 +1177,7 @@ def _draw_next_frame(self, framedata, blit):
11661177 def _init_draw (self ):
11671178 # Initial draw to clear the frame. Also used by the blitting code
11681179 # when a clean base is required.
1169- pass
1180+ self . _draw_was_started = True
11701181
11711182 def _pre_draw (self , framedata , blit ):
11721183 # Perform any cleaning or whatnot before the drawing of the frame.
@@ -1484,6 +1495,7 @@ def __init__(self, fig, artists, *args, **kwargs):
14841495 super ().__init__ (fig , * args , ** kwargs )
14851496
14861497 def _init_draw (self ):
1498+ super ()._init_draw ()
14871499 # Make all the artists involved in *any* frame invisible
14881500 figs = set ()
14891501 for f in self .new_frame_seq ():
@@ -1695,6 +1707,7 @@ def gen():
16951707 return gen ()
16961708
16971709 def _init_draw (self ):
1710+ super ()._init_draw ()
16981711 # Initialize the drawing either using the given init_func or by
16991712 # calling the draw function with the first item of the frame sequence.
17001713 # For blitting, the init_func should return a sequence of modified
0 commit comments