@@ -602,26 +602,18 @@ def get_figlabels():
602
602
603
603
604
604
def get_current_fig_manager ():
605
- """
606
- Return the figure manager of the active figure.
607
-
608
- If there is currently no active figure, a new one is created.
609
- """
610
- figManager = _pylab_helpers .Gcf .get_active ()
611
- if figManager is None :
612
- gcf () # creates an active figure as a side effect
613
- figManager = _pylab_helpers .Gcf .get_active ()
614
- return figManager
605
+ """Return ``gcf().canvas.manager``, the current figure's manager."""
606
+ return gcf ().canvas .manager
615
607
616
608
617
609
@docstring .copy (FigureCanvasBase .mpl_connect )
618
610
def connect (s , func ):
619
- return get_current_fig_manager ().canvas .mpl_connect (s , func )
611
+ return gcf ().canvas .mpl_connect (s , func )
620
612
621
613
622
614
@docstring .copy (FigureCanvasBase .mpl_disconnect )
623
615
def disconnect (cid ):
624
- return get_current_fig_manager ().canvas .mpl_disconnect (cid )
616
+ return gcf ().canvas .mpl_disconnect (cid )
625
617
626
618
627
619
def close (fig = None ):
@@ -683,7 +675,7 @@ def draw():
683
675
This is equivalent to calling ``fig.canvas.draw_idle()``, where ``fig`` is
684
676
the current figure.
685
677
"""
686
- get_current_fig_manager ().canvas .draw_idle ()
678
+ gcf ().canvas .draw_idle ()
687
679
688
680
689
681
@docstring .copy (Figure .savefig )
@@ -1262,25 +1254,19 @@ def subplot_tool(targetfig=None):
1262
1254
1263
1255
A :class:`matplotlib.widgets.SubplotTool` instance is returned.
1264
1256
"""
1265
- tbar = rcParams ['toolbar' ] # turn off navigation toolbar for the toolfig
1266
- rcParams ['toolbar' ] = 'None'
1267
1257
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' )
1258
+ targetfig = gcf ()
1277
1259
1260
+ tbar = rcParams ['toolbar' ] # Turn off navigation toolbar for the toolfig.
1261
+ rcParams ['toolbar' ] = 'None'
1278
1262
toolfig = figure (figsize = (6 , 3 ))
1279
1263
toolfig .subplots_adjust (top = 0.9 )
1280
- ret = SubplotTool (targetfig , toolfig )
1281
1264
rcParams ['toolbar' ] = tbar
1282
- _pylab_helpers .Gcf .set_active (manager ) # restore the current figure
1283
- return ret
1265
+
1266
+ if hasattr (targetfig .canvas , "manager" ): # Restore the current figure.
1267
+ _pylab_helpers .Gcf .set_active (targetfig .canvas .manager )
1268
+
1269
+ return SubplotTool (targetfig , toolfig )
1284
1270
1285
1271
1286
1272
def tight_layout (pad = 1.08 , h_pad = None , w_pad = None , rect = None ):
0 commit comments