Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f37d4f

Browse files
authored
Merge pull request #14014 from timhoffm/pyplot-subplot-figure
Disallow figure argument for pyplot.subplot() and Figure.add_subplot()
2 parents 2c22cc6 + 2193652 commit 0f37d4f

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
API changes
2+
```````````
3+
4+
`.Figure.add_subplot()` and `.pyplot.subplot()` do not accept a `figure`
5+
keyword argument anymore. It only used to work anyway if the passed figure
6+
was ``self`` or the current figure, respectively.

lib/matplotlib/figure.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,9 +1307,9 @@ def add_subplot(self, *args, **kwargs):
13071307
Other Parameters
13081308
----------------
13091309
**kwargs
1310-
This method also takes the keyword arguments for
1311-
the returned axes base class. The keyword arguments for the
1312-
rectilinear base class `~.axes.Axes` can be found in
1310+
This method also takes the keyword arguments for the returned axes
1311+
base class; except for the *figure* argument. The keyword arguments
1312+
for the rectilinear base class `~.axes.Axes` can be found in
13131313
the following table but there might also be other keyword
13141314
arguments if another projection is used.
13151315
@@ -1378,6 +1378,12 @@ def add_subplot(self, *args, **kwargs):
13781378
"three-digit number, not {}".format(args[0]))
13791379
args = tuple(map(int, str(args[0])))
13801380

1381+
if 'figure' in kwargs:
1382+
# Axes itself allows for a 'figure' kwarg, but since we want to
1383+
# bind the created Axes to self, it is not allowed here.
1384+
raise TypeError(
1385+
"add_subplot() got an unexpected keyword argument 'figure'")
1386+
13811387
if isinstance(args[0], SubplotBase):
13821388

13831389
a = args[0]

lib/matplotlib/pyplot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,9 @@ def subplot(*args, **kwargs):
929929
Other Parameters
930930
----------------
931931
**kwargs
932-
This method also takes the keyword arguments for
933-
the returned axes base class. The keyword arguments for the
934-
rectilinear base class `~.axes.Axes` can be found in
932+
This method also takes the keyword arguments for the returned axes
933+
base class; except for the *figure* argument. The keyword arguments
934+
for the rectilinear base class `~.axes.Axes` can be found in
935935
the following table but there might also be other keyword
936936
arguments if another projection is used.
937937

0 commit comments

Comments
 (0)