8000 Deprecate add_subplot(<no positional args>) silently doing nothing. · matplotlib/matplotlib@9eb7f87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9eb7f87

Browse files
committed
Deprecate add_subplot(<no positional args>) silently doing nothing.
To avoid head-scratching when `add_subplot(projection="3d")` does nothing (the correct call is `add_subplot(111, projection="3d")`).
1 parent de38ef2 commit 9eb7f87

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Behavior changes
2+
````````````````
3+
4+
Calling `.Figure.add_subplot()` with no positional arguments used to do
5+
nothing; this now is equivalent to calling ``add_subplot(111)`` instead.

lib/matplotlib/figure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,14 +1311,14 @@ def add_subplot(self, *args, **kwargs):
13111311
--------
13121312
::
13131313
1314-
fig=plt.figure()
1314+
fig = plt.figure()
13151315
fig.add_subplot(221)
13161316
13171317
# equivalent but more general
1318-
ax1=fig.add_subplot(2, 2, 1)
1318+
ax1 = fig.add_subplot(2, 2, 1)
13191319
13201320
# add a subplot with no frame
1321-
ax2=fig.add_subplot(222, frameon=False)
1321+
ax2 = fig.add_subplot(222, frameon=False)
13221322
13231323
# add a polar subplot
13241324
fig.add_subplot(223, projection='polar')
@@ -1333,7 +1333,7 @@ def add_subplot(self, *args, **kwargs):
13331333
fig.add_subplot(ax2)
13341334
"""
13351335
if not len(args):
1336-
return
1336+
args = (1, 1, 1)
13371337

13381338
if len(args) == 1 and isinstance(args[0], Integral):
13391339
if not 100 <= args[0] <= 999:

lib/matplotlib/tests/test_figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_clf_keyword():
116116
def test_figure():
117117
# named figure support
118118
fig = plt.figure('today')
119-
ax = fig.add_subplot(111)
119+
ax = fig.add_subplot()
120120
ax.set_title(fig.get_label())
121121
ax.plot(np.arange(5))
122122
# plot red line in a different figure.

0 commit comments

Comments
 (0)
0