Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a84b905

Browse files
authored
Merge pull request #14085 from anntzer/get_current_figure_manager
Deprecate get_current_fig_manager().
2 parents e285dde + e615fe5 commit a84b905

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

examples/misc/agg_buffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
plt.plot([1, 2, 3])
1616

17-
canvas = plt.get_current_fig_manager().canvas
17+
canvas = plt.gcf().canvas
1818

1919
agg = canvas.switch_backends(FigureCanvasAgg)
2020
agg.draw()

lib/matplotlib/pyplot.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -602,26 +602,18 @@ def get_figlabels():
602602

603603

604604
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
615607

616608

617609
@docstring.copy(FigureCanvasBase.mpl_connect)
618610
def connect(s, func):
619-
return get_current_fig_manager().canvas.mpl_connect(s, func)
611+
return gcf().canvas.mpl_connect(s, func)
620612

621613

622614
@docstring.copy(FigureCanvasBase.mpl_disconnect)
623615
def disconnect(cid):
624-
return get_current_fig_manager().canvas.mpl_disconnect(cid)
616+
return gcf().canvas.mpl_disconnect(cid)
625617

626618

627619
def close(fig=None):
@@ -683,7 +675,7 @@ def draw():
683675
This is equivalent to calling ``fig.canvas.draw_idle()``, where ``fig`` is
684676
the current figure.
685677
"""
686-
get_current_fig_manager().canvas.draw_idle()
678+
gcf().canvas.draw_idle()
687679

688680

689681
@docstring.copy(Figure.savefig)
@@ -1262,25 +1254,19 @@ def subplot_tool(targetfig=None):
12621254
12631255
A :class:`matplotlib.widgets.SubplotTool` instance is returned.
12641256
"""
1265-
tbar = rcParams['toolbar'] # turn off navigation toolbar for the toolfig
1266-
rcParams['toolbar'] = 'None'
12671257
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()
12771259

1260+
tbar = rcParams['toolbar'] # Turn off navigation toolbar for the toolfig.
1261+
rcParams['toolbar'] = 'None'
12781262
toolfig = figure(figsize=(6, 3))
12791263
toolfig.subplots_adjust(top=0.9)
1280-
ret = SubplotTool(targetfig, toolfig)
12811264
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)
12841270

12851271

12861272
def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None):

0 commit comments

Comments
 (0)