We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2960490 commit 385e1a5Copy full SHA for 385e1a5
lib/matplotlib/pyplot.py
@@ -1232,6 +1232,7 @@ def subplot(*args, **kwargs):
1232
# If no existing axes matches, then create a new one.
1233
if ax is None or getattr(ax, '_init_kwargs', {}) != kwargs:
1234
ax = fig.add_subplot(*args, **kwargs)
1235
+ fig.sca(ax)
1236
1237
bbox = ax.bbox
1238
axes_to_delete = []
lib/matplotlib/tests/test_pyplot.py
@@ -153,3 +153,12 @@ def test_nested_ion_ioff():
153
with plt.ioff():
154
plt.ion()
155
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
164
0 commit comments