@@ -143,6 +143,8 @@ def _register_fig(self, fig):
143
143
fignum = next (self ._count )
144
144
if fig .get_label () == "" :
145
145
fig .set_label (f"{ self ._prefix } { fignum :d} " )
146
+ # TODO: is there a better way to track this than monkey patching?
147
+ fig ._mpl_gui_fignum = fignum
146
148
return fig
147
149
148
150
@property
@@ -171,7 +173,7 @@ def by_number(self):
171
173
Return a dictionary of the current mapping number -> figures.
172
174
173
175
"""
174
- self ._promote_and_number ()
176
+ self ._ensure_all_figures_promoted ()
175
177
return {fig .canvas .manager .num : fig for fig in self .figures }
176
178
177
179
@functools .wraps (figure )
@@ -189,17 +191,10 @@ def subplot_mosaic(self, *args, **kwargs):
189
191
fig , axd = subplot_mosaic (* args , ** kwargs )
190
192
return self ._register_fig (fig ), axd
191
193
192
- def _promote_and_number (self ):
193
- promoted_figures = []
194
- unpromotod_figures = []
194
+ def _ensure_all_figures_promoted (self ):
195
195
for f in self .figures :
196
- if f .canvas .manager is not None :
197
- promoted_figures .append (f )
198
- else :
199
- unpromotod_figures .append (f )
200
- next_num = max ([f .canvas .manager .num for f in promoted_figures ], default = 0 ) + 1
201
- for num , fig in enumerate (unpromotod_figures , start = next_num ):
202
- promote_figure (fig , num = num )
196
+ if f .canvas .manager is None :
197
+ promote_figure (f , num = f ._mpl_gui_fignum )
203
198
204
199
def show_all (self , * , block = None , timeout = None ):
205
200
"""
@@ -232,7 +227,7 @@ def show_all(self, *, block=None, timeout=None):
232
227
233
228
if timeout is None :
234
229
timeout = self ._timeout
235
- self ._promote_and_number ()
230
+ self ._ensure_all_figures_promoted ()
236
231
show (self .figures , block = self ._block , timeout = self ._timeout )
237
232
238
233
# alias to easy pyplot compatibility
0 commit comments