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

Skip to content

Commit 86fe348

Browse files
committed
Deprecate get_current_figure_manager().
It's longer to type(!) than its actual implementation (``gcf().canvas.manager``), and mixes the pyplot and the OO-interfaces. Also make ``plt.subplot_tool`` work even for non-pyplot-managed figures -- there's no reason not to, it's just that such figures cannot be made the "current" pyplot figure.
1 parent c1a3c03 commit 86fe348

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
``plt.get_current_figure_manager()`` is deprecated, in favor of
5+
``plt.gcf().canvas.manager``.

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: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ def get_figlabels():
601601
return [m.canvas.figure.get_label() for m in figManagers]
602602

603603

604+
@cbook.deprecated("3.2", alternative="gcf().canvas.manager")
604605
def get_current_fig_manager():
605606
"""
606607
Return the figure manager of the active figure.
@@ -616,12 +617,12 @@ def get_current_fig_manager():
616617

617618
@docstring.copy(FigureCanvasBase.mpl_connect)
618619
def connect(s, func):
619-
return get_current_fig_manager().canvas.mpl_connect(s, func)
620+
return gcf().canvas.mpl_connect(s, func)
620621

621622

622623
@docstring.copy(FigureCanvasBase.mpl_disconnect)
623624
def disconnect(cid):
624-
return get_current_fig_manager().canvas.mpl_disconnect(cid)
625+
return gcf().canvas.mpl_disconnect(cid)
625626

626627

627628
def close(fig=None):
@@ -683,7 +684,7 @@ def draw():
683684
This is equivalent to calling ``fig.canvas.draw_idle()``, where ``fig`` is
684685
the current figure.
685686
"""
686-
get_current_fig_manager().canvas.draw_idle()
687+
gcf().canvas.draw_idle()
687688

688689

689690
@docstring.copy(Figure.savefig)
@@ -1262,25 +1263,19 @@ def subplot_tool(targetfig=None):
12621263
12631264
A :class:`matplotlib.widgets.SubplotTool` instance is returned.
12641265
"""
1265-
tbar = rcParams['toolbar'] # turn off navigation toolbar for the toolfig
1266-
rcParams['toolbar'] = 'None'
12671266
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()
12771268

1269+
tbar = rcParams['toolbar'] # turn off navigation toolbar for the toolfig
1270+
rcParams['toolbar'] = 'None'
12781271
toolfig = figure(figsize=(6, 3))
12791272
toolfig.subplots_adjust(top=0.9)
1280-
ret = SubplotTool(targetfig, toolfig)
12811273
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)
12841279

12851280

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

0 commit comments

Comments
 (0)