@@ -601,6 +601,7 @@ def get_figlabels():
601
601
return [m .canvas .figure .get_label () for m in figManagers ]
602
602
603
603
604
+ @cbook .deprecated ("3.2" , alternative = "gcf().canvas.manager" )
604
605
def get_current_fig_manager ():
605
606
"""
606
607
Return the figure manager of the active figure.
@@ -616,12 +617,12 @@ def get_current_fig_manager():
616
617
617
618
@docstring .copy (FigureCanvasBase .mpl_connect )
618
619
def connect (s , func ):
619
- return get_current_fig_manager ().canvas .mpl_connect (s , func )
620
+ return gcf ().canvas .mpl_connect (s , func )
620
621
621
622
622
623
@docstring .copy (FigureCanvasBase .mpl_disconnect )
623
624
def disconnect (cid ):
624
- return get_current_fig_manager ().canvas .mpl_disconnect (cid )
625
+ return gcf ().canvas .mpl_disconnect (cid )
625
626
626
627
627
628
def close (fig = None ):
@@ -683,7 +684,7 @@ def draw():
683
684
This is equivalent to calling ``fig.canvas.draw_idle()``, where ``fig`` is
684
685
the current figure.
685
686
"""
686
- get_current_fig_manager ().canvas .draw_idle ()
687
+ gcf ().canvas .draw_idle ()
687
688
688
689
689
690
@docstring .copy (Figure .savefig )
@@ -1262,25 +1263,19 @@ def subplot_tool(targetfig=None):
1262
1263
1263
1264
A :class:`matplotlib.widgets.SubplotTool` instance is returned.
1264
1265
"""
1265
- tbar = rcParams ['toolbar' ] # turn off navigation toolbar for the toolfig
1266
- rcParams ['toolbar' ] = 'None'
1267
1266
if targetfig is None :
1268
- manager = get_current_fig_manager ()
1269
- targetfig = manager .canvas .figure
1270
- else :
1271
- # find the manager for this figure
1272
- for manager in _pylab_helpers .Gcf ._activeQue :
1273
- if manager .canvas .figure == targetfig :
1274
- break
1275
- else :
1276
- raise RuntimeError ('Could not find manager for targetfig' )
1267
+ targetfig = gcf ()
1277
1268
1269
+ tbar = rcParams ['toolbar' ] # turn off navigation toolbar for the toolfig
1270
+ rcParams ['toolbar' ] = 'None'
1278
1271
toolfig = figure (figsize = (6 , 3 ))
1279
1272
toolfig .subplots_adjust (top = 0.9 )
1280
- ret = SubplotTool (targetfig , toolfig )
1281
1273
rcParams ['toolbar' ] = tbar
1282
- _pylab_helpers .Gcf .set_active (manager ) # restore the current figure
1283
- return ret
1274
+
1275
+ if hasattr (targetfig .canvas , "manager" ): # Restore the current figure
1276
+ _pylab_helpers .Gcf .set_active (targetfig .canvas .manager )
1277
+
1278
+ return SubplotTool (targetfig , toolfig )
1284
1279
1285
1280
1286
1281
def tight_layout (pad = 1.08 , h_pad = None , w_pad = None , rect = None ):
0 commit comments