Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 040e86d

Browse filesBrowse files
committed
FIX: set sca when re-using as Axes with pyplot.subplot
1 parent 5b95065 commit 040e86d
Copy full SHA for 040e86d

File tree

Expand file treeCollapse file tree

2 files changed

+10
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-0
lines changed

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@ def subplot(*args, **kwargs):
12331233
# If no existing axes matches, then create a new one.
12341234
if ax is None or getattr(ax, '_projection_init', ()) != key:
12351235
ax = fig.add_subplot(*args, **kwargs)
1236+
fig.sca(ax)
12361237

12371238
bbox = ax.bbox
12381239
axes_to_delete = []

‎lib/matplotlib/tests/test_pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_pyplot.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,12 @@ def test_close():
161161
except TypeError as e:
162162
assert str(e) == "close() argument must be a Figure, an int, " \
163163
"a string, or None, not <class 'float'>"
164+
165+
166+
def test_subplot_reuse():
167+
ax1 = plt.subplot(121)
168+
assert ax1 is plt.gca()
169+
ax2 = plt.subplot(122)
170+
assert ax2 is plt.gca()
171+
ax1 = plt.subplot(121)
172+
assert ax1 is plt.gca()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.