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 385e1a5

Browse filesBrowse files
committed
FIX: set sca when re-using as Axes with pyplot.subplot
1 parent 2960490 commit 385e1a5
Copy full SHA for 385e1a5

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
@@ -1232,6 +1232,7 @@ def subplot(*args, **kwargs):
12321232
# If no existing axes matches, then create a new one.
12331233
if ax is None or getattr(ax, '_init_kwargs', {}) != kwargs:
12341234
ax = fig.add_subplot(*args, **kwargs)
1235+
fig.sca(ax)
12351236

12361237
bbox = ax.bbox
12371238
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
@@ -153,3 +153,12 @@ def test_nested_ion_ioff():
153153
with plt.ioff():
154154
plt.ion()
155155
assert not mpl.is_interactive()
156+
157+
158+
def test_subplot_reuse():
159+
ax1 = plt.subplot(121)
160+
assert ax1 is plt.gca()
161+
ax2 = plt.subplot(122)
162+
assert ax2 is plt.gca()
163+
ax1 = plt.subplot(121)
164+
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.