Fix pyplot.axis(ax) when ax is in other figure. #8043

Merged
merged 4 commits into from Feb 11, 2017
View
@@ -875,7 +875,8 @@ def axes(*args, **kwargs):
color for the axis, default white.
- ``axes(h)`` where *h* is an axes instance makes *h* the current
- axis. An :class:`~matplotlib.axes.Axes` instance is returned.
+ axis and the parent of *h* the current figure.
+ An :class:`~matplotlib.axes.Axes` instance is returned.
========= ============== ==============================================
kwarg Accepts Description
@@ -909,7 +910,8 @@ def axes(*args, **kwargs):
arg = args[0]
if isinstance(arg, Axes):
- a = gcf().sca(arg)
+ sca(arg)
+ a = arg
else:
rect = arg
a = gcf().add_axes(rect, **kwargs)
@@ -1477,6 +1477,17 @@ def _as_mpl_axes(self):
plt.close()
+def test_pyplot_axes():
+ # test focusing of Axes in other Figure
+ fig1, ax1 = plt.subplots()
+ fig2, ax2 = plt.subplots()
+ assert ax1 is plt.axes(ax1)
+ assert ax1 is plt.gca()
+ assert fig1 is plt.gcf()
+ plt.close(fig1)
+ plt.close(fig2)
+
+
@image_comparison(baseline_images=['log_scales'])
def test_log_scales():
fig = plt.figure()