Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1ad9e60

Browse filesBrowse files
committed
DOC: update pyplot.subplot docstring
1 parent 385e1a5 commit 1ad9e60
Copy full SHA for 1ad9e60

File tree

Expand file treeCollapse file tree

2 files changed

+30
-33
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+30
-33
lines changed

‎doc/users/next_whats_new/axes_kwargs_collision.rst

Copy file name to clipboardExpand all lines: doc/users/next_whats_new/axes_kwargs_collision.rst
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ Changes to behavior of Axes creation methods (``gca()``, ``add_axes()``, ``add_s
33

44
The behavior of the functions to create new axes (`.pyplot.axes`,
55
`.pyplot.subplot`, `.figure.Figure.add_axes`,
6-
`.figure.Figure.add_subplot`) has changed. In the past, these functions would
7-
detect if you were attempting to create Axes with the same keyword arguments as
8-
already-existing axes in the current figure, and if so, they would return the
9-
existing Axes. Now, these functions will always create new Axes. A special
10-
exception is `.pyplot.subplot`, which will reuse any existing subplot with a
11-
matching subplot spec. However, if there is a subplot with a matching subplot
12-
spec, then that subplot will be returned, even if the keyword arguments with
13-
which it was created differ.
6+
`.figure.Figure.add_subplot`) has changed. In the past, these
7+
functions would detect if you were attempting to create Axes with the
8+
same keyword arguments as already-existing axes in the current figure,
9+
and if so, they would return the existing Axes. Now, `.pyplot.axes`,
10+
`.figure.Figure.add_axes`, and `.figure.Figure.add_subplot` will
11+
always create new Axes. `.pyplot.subplot` will continue reuse an
12+
existing Axes with a matching subplot spec and equal *kwargs*.
1413

1514
Correspondingly, the behavior of the functions to get the current Axes
16-
(`.pyplot.gca`, `.figure.Figure.gca`) has changed. In the past, these functions
17-
accepted keyword arguments. If the keyword arguments matched an
18-
already-existing Axes, then that Axes would be returned, otherwise new Axes
19-
would be created with those keyword arguments. Now, the keyword arguments are
20-
only considered if there are no axes at all in the current figure. In a future
21-
release, these functions will not accept keyword arguments at all.
15+
(`.pyplot.gca`, `.figure.Figure.gca`) has changed. In the past, these
16+
functions accepted keyword arguments. If the keyword arguments
17+
matched an already-existing Axes, then that Axes would be returned,
18+
otherwise new Axes would be created with those keyword arguments.
19+
Now, the keyword arguments are only considered if there are no axes at
20+
all in the current figure. In a future release, these functions will
21+
not accept keyword arguments at all.

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+16-19Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,10 @@ def cla():
10721072
@docstring.dedent_interpd
10731073
def subplot(*args, **kwargs):
10741074
"""
1075-
Add a subplot to the current figure.
1075+
Add an Axes to the current figure or retrieve an existing Axes.
10761076
1077-
Wrapper of `.Figure.add_subplot` with a difference in
1078-
behavior explained in the notes section.
1077+
This is a wrapper of `.Figure.add_subplot` which provides additional
1078+
behavior when working with the implicit API (see the notes section).
10791079
10801080
Call signatures::
10811081
@@ -1142,8 +1142,9 @@ def subplot(*args, **kwargs):
11421142
11431143
Notes
11441144
-----
1145-
Creating a subplot will delete any pre-existing subplot that overlaps
1146-
with it beyond sharing a boundary::
1145+
1146+
Creating a new Axes will delete any pre-existing Axes that
1147+
overlaps with it beyond sharing a boundary::
11471148
11481149
import matplotlib.pyplot as plt
11491150
# plot a line, implicitly creating a subplot(111)
@@ -1156,18 +1157,10 @@ def subplot(*args, **kwargs):
11561157
If you do not want this behavior, use the `.Figure.add_subplot` method
11571158
or the `.pyplot.axes` function instead.
11581159
1159-
If the figure already has a subplot with key (*args*,
1160-
*kwargs*) then it will simply make that subplot current and
1161-
return it. This behavior is deprecated. Meanwhile, if you do
1162-
not want this behavior (i.e., you want to force the creation of a
1163-
new subplot), you must use a unique set of args and kwargs. The axes
1164-
*label* attribute has been exposed for this purpose: if you want
1165-
two subplots that are otherwise identical to be added to the figure,
1166-
make sure you give them unique labels.
1167-
1168-
In rare circumstances, `.Figure.add_subplot` may be called with a single
1169-
argument, a subplot axes instance already created in the
1170-
present figure but not in the figure's list of axes.
1160+
If the current Figure already has an Axes created with the same
1161+
(*args*, *kwargs*) the existing Axes will be made current and
1162+
returned. If the values in *kwargs* are mutable this may not
1163+
behave as expected.
11711164
11721165
See Also
11731166
--------
@@ -1183,10 +1176,10 @@ def subplot(*args, **kwargs):
11831176
plt.subplot(221)
11841177
11851178
# equivalent but more general
1186-
ax1=plt.subplot(2, 2, 1)
1179+
ax1 = plt.subplot(2, 2, 1)
11871180
11881181
# add a subplot with no frame
1189-
ax2=plt.subplot(222, frameon=False)
1182+
ax2 = plt.subplot(222, frameon=False)
11901183
11911184
# add a polar subplot
11921185
plt.subplot(223, projection='polar')
@@ -1199,6 +1192,10 @@ def subplot(*args, **kwargs):
11991192
12001193
# add ax2 to the figure again
12011194
plt.subplot(ax2)
1195+
1196+
# make the first axes "current" again
1197+
plt.subplot(221)
1198+
12021199
"""
12031200

12041201
# if subplot called without arguments, create subplot(1, 1, 1)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.