Skip to content

Commit ffb36ba

Browse files
committed
DOC: Add illustration to Figure.subplots_adjust
Closes #23005.
1 parent 4b35874 commit ffb36ba

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import matplotlib.pyplot as plt
2+
3+
def arrow(p1, p2, **props):
4+
axs[0, 0].annotate(
5+
"", p1, p2, xycoords='figure fraction',
6+
arrowprops=dict(arrowstyle="<->", shrinkA=0, shrinkB=0, **props))
7+
8+
fig, axs = plt.subplots(2, 2, figsize=(6.5, 4))
9+
fig.set_facecolor('lightblue')
10+
fig.subplots_adjust(0.1, 0.1, 0.9, 0.9, 0.4, 0.4)
11+
for ax in axs.flat:
12+
ax.set(xticks=[], yticks=[])
13+
14+
arrow((0, 0.75), (0.1, 0.75)) # left
15+
arrow((0.435, 0.75), (0.565, 0.75)) # wspace
16+
arrow((0.9, 0.75), (1, 0.75)) # right
17+
fig.text(0.05, 0.7, "left", ha="center")
18+
fig.text(0.5, 0.7, "wspace", ha="center")
19+
fig.text(0.95, 0.7, "right", ha="center")
20+
21+
arrow((0.25, 0), (0.25, 0.1)) # bottom
22+
arrow((0.25, 0.435), (0.25, 0.565)) # hspace
23+
arrow((0.25, 0.9), (0.25, 1)) # top
24+
fig.text(0.28, 0.05, "bottom", va="center")
25+
fig.text(0.28, 0.5, "hspace", va="center")
26+
fig.text(0.28, 0.95, "top", va="center")

lib/matplotlib/figure.py

+4
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,10 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
13221322
Unset parameters are left unmodified; initial values are given by
13231323
:rc:`figure.subplot.[name]`.
13241324
1325+
The following plot illustrates the effect of the parameters:
1326+
1327+
.. plot:: _embedded_plots/figure_subplots_adjust.py
1328+
13251329
Parameters
13261330
----------
13271331
left : float, optional

0 commit comments

Comments
 (0)