Skip to content

Commit 9f6f022

Browse files
committed
Simplify sca().
One can just lookup the manager on the figure instance instead of iterating over all managers.
1 parent 030157c commit 9f6f022

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -838,17 +838,12 @@ def delaxes(ax=None):
838838

839839
def sca(ax):
840840
"""
841-
Set the current Axes instance to *ax*.
842-
843-
The current Figure is updated to the parent of *ax*.
841+
Set the current Axes to *ax* and the current Figure to the parent of *ax*.
844842
"""
845-
managers = _pylab_helpers.Gcf.get_all_fig_managers()
846-
for m in managers:
847-
if ax in m.canvas.figure.axes:
848-
_pylab_helpers.Gcf.set_active(m)
849-
m.canvas.figure.sca(ax)
850-
return
851-
raise ValueError("Axes instance argument was not found in a figure")
843+
if not hasattr(ax.figure.canvas, "manager"):
844+
raise ValueError("Axes parent figure is not managed by pyplot")
845+
_pylab_helpers.Gcf.set_active(ax.figure.canvas.manager)
846+
ax.figure.sca(ax)
852847

853848

854849
def gca(**kwargs):

0 commit comments

Comments
 (0)