28
28
import sys
29
29
from tempfile import TemporaryDirectory
30
30
import uuid
31
+ import warnings
31
32
32
33
import numpy as np
33
34
@@ -907,6 +908,8 @@ class Animation:
907
908
"""
908
909
909
910
def __init__ (self , fig , event_source = None , blit = False ):
911
+ self ._draw_was_started = False
912
+
910
913
self ._fig = fig
911
914
# Disables blitting for backends that don't support it. This
912
915
# allows users to request it if available, but still have a
@@ -931,6 +934,14 @@ def __init__(self, fig, event_source=None, blit=False):
931
934
if self ._blit :
932
935
self ._setup_blit ()
933
936
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
+
934
945
def _start (self , * args ):
935
946
"""
936
947
Starts interactive animation. Adds the draw frame command to the GUI
@@ -1166,7 +1177,7 @@ def _draw_next_frame(self, framedata, blit):
1166
1177
def _init_draw (self ):
1167
1178
# Initial draw to clear the frame. Also used by the blitting code
1168
1179
# when a clean base is required.
1169
- pass
1180
+ self . _draw_was_started = True
1170
1181
1171
1182
def _pre_draw (self , framedata , blit ):
1172
1183
# Perform any cleaning or whatnot before the drawing of the frame.
@@ -1484,6 +1495,7 @@ def __init__(self, fig, artists, *args, **kwargs):
1484
1495
super ().__init__ (fig , * args , ** kwargs )
1485
1496
1486
1497
def _init_draw (self ):
1498
+ super ()._init_draw ()
1487
1499
# Make all the artists involved in *any* frame invisible
1488
1500
figs = set ()
1489
1501
for f in self .new_frame_seq ():
@@ -1695,6 +1707,7 @@ def gen():
1695
1707
return gen ()
1696
1708
1697
1709
def _init_draw (self ):
1710
+ super ()._init_draw ()
1698
1711
# Initialize the drawing either using the given init_func or by
1699
1712
# calling the draw function with the first item of the frame sequence.
1700
1713
# For blitting, the init_func should return a sequence of modified
0 commit comments