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 ._anim_was_inited = 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,11 @@ 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 , '_anim_was_inited' , True ):
939
+ warnings .warn ('Animation was garbage-collected before saving any '
940
+ 'frames; did you forget to save it to a variable?' )
941
+
934
942
def _start (self , * args ):
935
943
"""
936
944
Starts interactive animation. Adds the draw frame command to the GUI
@@ -1166,7 +1174,7 @@ def _draw_next_frame(self, framedata, blit):
1166
1174
def _init_draw (self ):
1167
1175
# Initial draw to clear the frame. Also used by the blitting code
1168
1176
# when a clean base is required.
1169
- pass
1177
+ self . _anim_was_inited = True
1170
1178
1171
1179
def _pre_draw (self , framedata , blit ):
1172
1180
# Perform any cleaning or whatnot before the drawing of the frame.
@@ -1484,6 +1492,7 @@ def __init__(self, fig, artists, *args, **kwargs):
1484
1492
super ().__init__ (fig , * args , ** kwargs )
1485
1493
1486
1494
def _init_draw (self ):
1495
+ super ()._init_draw ()
1487
1496
# Make all the artists involved in *any* frame invisible
1488
1497
figs = set ()
1489
1498
for f in self .new_frame_seq ():
@@ -1695,6 +1704,7 @@ def gen():
1695
1704
return gen ()
1696
1705
1697
1706
def _init_draw (self ):
1707
+ super ()._init_draw ()
1698
1708
# Initialize the drawing either using the given init_func or by
1699
1709
# calling the draw function with the first item of the frame sequence.
1700
1710
# For blitting, the init_func should return a sequence of modified
0 commit comments