@@ -922,9 +922,11 @@ def _start(self, *args):
922
922
Starts interactive animation. Adds the draw frame command to the GUI
923
923
handler, calls show to start the event loop.
924
924
'''
925
+ # Do not start the event source if saving() it.
926
+ if self ._fig .canvas .is_saving ():
927
+ return
925
928
# First disconnect our draw event handler
926
929
self ._fig .canvas .mpl_disconnect (self ._first_draw_id )
927
- self ._first_draw_id = None # So we can check on save
928
930
929
931
# Now do any initial draw
930
932
self ._init_draw ()
@@ -1040,14 +1042,6 @@ def func(current_frame: int, total_frames: int) -> Any
1040
1042
if savefig_kwargs is None :
1041
1043
savefig_kwargs = {}
1042
1044
1043
- # Need to disconnect the first draw callback, since we'll be doing
1044
- # draws. Otherwise, we'll end up starting the animation.
1045
- if self ._first_draw_id is not None :
1046
- self ._fig .canvas .mpl_disconnect (self ._first_draw_id )
1047
- reconnect_first_draw = True
1048
- else :
1049
- reconnect_first_draw = False
1050
-
1051
1045
if fps is None and hasattr (self , '_interval' ):
1052
1046
# Convert interval in ms to frames per second
1053
1047
fps = 1000. / self ._interval
@@ -1106,8 +1100,11 @@ def func(current_frame: int, total_frames: int) -> Any
1106
1100
_log .info ("Disabling savefig.bbox = 'tight', as it may cause "
1107
1101
"frame size to vary, which is inappropriate for "
1108
1102
"animation." )
1103
+ # canvas._is_saving = True makes the draw_event animation-starting
1104
+ # callback a no-op.
1109
1105
with mpl .rc_context ({'savefig.bbox' : None }), \
1110
- writer .saving (self ._fig , filename , dpi ):
1106
+ writer .saving (self ._fig , filename , dpi ), \
1107
+ cbook ._setattr_cm (self ._fig .canvas , _is_saving = True ):
1111
1108
for anim in all_anim :
1112
1109
anim ._init_draw () # Clear the initial frame
1113
1110
frame_number = 0
@@ -1128,11 +1125,6 @@ def func(current_frame: int, total_frames: int) -> Any
1128
1125
frame_number += 1
1129
1126
writer .grab_frame (** savefig_kwargs )
1130
1127
1131
- # Reconnect signal for first draw if necessary
1132
- if reconnect_first_draw :
1133
- self ._first_draw_id = self ._fig .canvas .mpl_connect ('draw_event' ,
1134
- self ._start )
1135
-
1136
1128
def _step (self , * args ):
1137
1129
'''
1138
1130
Handler for getting events. By default, gets the next frame in the
0 commit comments