@@ -939,9 +939,11 @@ def _start(self, *args):
939
939
Starts interactive animation. Adds the draw frame command to the GUI
940
940
handler, calls show to start the event loop.
941
941
"""
942
+ # Do not start the event source if saving() it.
943
+ if self ._fig .canvas .is_saving ():
944
+ return
942
945
# First disconnect our draw event handler
943
946
self ._fig .canvas .mpl_disconnect (self ._first_draw_id )
944
- self ._first_draw_id = None # So we can check on save
945
947
946
948
# Now do any initial draw
947
949
self ._init_draw ()
@@ -1057,14 +1059,6 @@ def func(current_frame: int, total_frames: int) -> Any
1057
1059
if savefig_kwargs is None :
1058
1060
savefig_kwargs = {}
1059
1061
1060
- # Need to disconnect the first draw callback, since we'll be doing
1061
- # draws. Otherwise, we'll end up starting the animation.
1062
- if self ._first_draw_id is not None :
1063
- self ._fig .canvas .mpl_disconnect (self ._first_draw_id )
1064
- reconnect_first_draw = True
1065
- else :
1066
- reconnect_first_draw = False
1067
-
1068
1062
if fps is None and hasattr (self , '_interval' ):
1069
1063
# Convert interval in ms to frames per second
1070
1064
fps = 1000. / self ._interval
@@ -1123,8 +1117,11 @@ def func(current_frame: int, total_frames: int) -> Any
1123
1117
_log .info ("Disabling savefig.bbox = 'tight', as it may cause "
1124
1118
"frame size to vary, which is inappropriate for "
1125
1119
"animation." )
1120
+ # canvas._is_saving = True makes the draw_event animation-starting
1121
+ # callback a no-op.
1126
1122
with mpl .rc_context ({'savefig.bbox' : None }), \
1127
- writer .saving (self ._fig , filename , dpi ):
1123
+ writer .saving (self ._fig , filename , dpi ), \
1124
+ cbook ._setattr_cm (self ._fig .canvas , _is_saving = True ):
1128
1125
for anim in all_anim :
1129
1126
anim ._init_draw () # Clear the initial frame
1130
1127
frame_number = 0
@@ -1145,11 +1142,6 @@ def func(current_frame: int, total_frames: int) -> Any
1145
1142
frame_number += 1
1146
1143
writer .grab_frame (** savefig_kwargs )
1147
1144
1148
- # Reconnect signal for first draw if necessary
1149
- if reconnect_first_draw :
1150
- self ._first_draw_id = self ._fig .canvas .mpl_connect ('draw_event' ,
1151
- self ._start )
1152
-
1153
1145
def _step (self , * args ):
1154
1146
"""
1155
1147
Handler for getting events. By default, gets the next frame in the
0 commit comments