Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down