Skip to content

Commit 87495f5

Browse files
authored
Merge pull request #15309 from anntzer/sca
Simplify sca().
2 parents a550200 + 9f6f022 commit 87495f5

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
@@ -813,17 +813,12 @@ def delaxes(ax=None):
813813

814814
def sca(ax):
815815
"""
816-
Set the current Axes instance to *ax*.
817-
818-
The current Figure is updated to the parent of *ax*.
816+
Set the current Axes to *ax* and the current Figure to the parent of *ax*.
819817
"""
820-
managers = _pylab_helpers.Gcf.get_all_fig_managers()
821-
for m in managers:
822-
if ax in m.canvas.figure.axes:
823-
_pylab_helpers.Gcf.set_active(m)
824-
m.canvas.figure.sca(ax)
825-
return
826-
raise ValueError("Axes instance argument was not found in a figure")
818+
if not hasattr(ax.figure.canvas, "manager"):
819+
raise ValueError("Axes parent figure is not managed by pyplot")
820+
_pylab_helpers.Gcf.set_active(ax.figure.canvas.manager)
821+
ax.figure.sca(ax)
827822

828823

829824
## More ways of creating axes ##

0 commit comments

Comments
 (0)