Skip to content
Closed
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
4 changes: 4 additions & 0 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,10 @@ def subplot(*args, **kwargs):
# If no existing axes match, then create a new one.
if ax is None:
ax = fig.add_subplot(*args, **kwargs)
elif kwargs:
_api.warn_external(f"An Axes with subplot spec {args} already exists. "
"The existing Axes will be returned, with all "
"keyword arguments ignored.")

bbox = ax.bbox
axes_to_delete = []
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,11 @@ def test_nested_ion_ioff():
with plt.ioff():
plt.ion()
assert not mpl.is_interactive()


def test_subplot_warning():
ax1 = plt.subplot(2, 1, 1)
with pytest.warns(UserWarning, match='An Axes with subplot spec '
r'\(2, 1, 1\) already exists'):
ax2 = plt.subplot(2, 1, 1, polar=True)
assert ax1 is ax2