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

Skip to content

Commit b73a94a

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 b73a94a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
Calling `.Figure.add_subplot()` with no positional arguments used to do
5+
nothing; this is deprecated.

lib/matplotlib/figure.py

Lines changed: 6 additions & 3 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,6 +1333,9 @@ def add_subplot(self, *args, **kwargs):
13331333
fig.add_subplot(ax2)
13341334
"""
13351335
if not len(args):
1336+
cbook.warn_deprecated("3.1", message=
1337+
"Support for calling add_subplot() with no arguments is "
1338+
"deprecated and will be removed %(removal)s.")
13361339
return
13371340

13381341
if len(args) == 1 and isinstance(args[0], Integral):

0 commit comments

Comments
 (0)
0