Skip to content

Commit e47efd1

Browse files
committed
FIX: set sca when re-using as Axes with pyplot.subplot
1 parent aa413a8 commit e47efd1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/matplotlib/pyplot.py

Lines 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 match, then create a new one.
12331233
if ax is None:
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

Lines 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)