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

Skip to content

Commit 9ef03bb

Browse files
committed
DOC: improvements to tight layout guide
1 parent 9e1d424 commit 9ef03bb

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

doc/users/tight_layout_guide.rst

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ of ticklabels, axis labels, and titles.
1313
Simple Example
1414
==============
1515

16-
In matplotlib location of axes (including subplots) are specified in
17-
normalized figure coordinate. It can happen that your axis labels or
18-
titles (or sometimes even ticklabels) go outside the figure area thus
16+
In matplotlib, the location of axes (including subplots) are specified in
17+
normalized figure coordinates. It can happen that your axis labels or
18+
titles (or sometimes even ticklabels) go outside the figure area, and are thus
1919
clipped.
2020

2121
.. plot::
@@ -35,7 +35,7 @@ clipped.
3535
fig, ax = plt.subplots()
3636
example_plot(ax, fontsize=24)
3737

38-
To prevent this, the location of axes need to be adjusted. For
38+
To prevent this, the location of axes needs to be adjusted. For
3939
subplots, this can be done by adjusting the subplot params
4040
(:ref:`howto-subplots-adjust`). Matplotlib v1.1 introduces a new
4141
command :func:`~matplotlib.pyplot.tight_layout` that does this
@@ -48,7 +48,7 @@ automatically for you.
4848
plt.tight_layout()
4949

5050
When you have multiple subplots, often you see labels of different
51-
axes overlaps each other.
51+
axes overlapping each other.
5252

5353
.. plot::
5454
:include-source:
@@ -62,8 +62,8 @@ axes overlaps each other.
6262
example_plot(ax4)
6363

6464

65-
*tight_layout* will also adjust spacing betweens subplots to minimize
66-
the overlaps.
65+
:func:`~matplotlib.pyplot.tight_layout` will also adjust spacing between
66+
subplots to minimize the overlaps.
6767

6868
.. plot::
6969
:include-source:
@@ -72,7 +72,7 @@ the overlaps.
7272
plt.tight_layout()
7373

7474
:func:`~matplotlib.pyplot.tight_layout` can take keyword arguments of
75-
*pad*, *w_pad* and *h_pad*. These controls the extra pad around the
75+
*pad*, *w_pad* and *h_pad*. These control the extra padding around the
7676
figure border and between subplots. The pads are specified in fraction
7777
of fontsize.
7878

@@ -83,9 +83,9 @@ of fontsize.
8383
plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)
8484

8585
:func:`~matplotlib.pyplot.tight_layout` will work even if the sizes of
86-
subplot are different as far as their grid specification is
87-
compatible. In the example below, *ax1* and *ax2* are subplots of 2x2
88-
grid, while *ax3* is of 1x2 grid.
86+
subplots are different as far as their grid specification is
87+
compatible. In the example below, *ax1* and *ax2* are subplots of a 2x2
88+
grid, while *ax3* is of a 1x2 grid.
8989

9090

9191
.. plot::
@@ -152,11 +152,13 @@ aspect != "auto" (e.g., axes with images).
152152
Caveats
153153
-------
154154

155-
* *tight_layout* only considers ticklabels, axis labels, and titles. Thus, other atists may be clipped and also may overlap.
155+
* :func:`~matplotlib.pyplot.tight_layout` only considers ticklabels, axis
156+
labels, and titles. Thus, other artists may be clipped and also may
157+
overlap.
156158

157159
* It assumes that the extra space needed for ticklabels, axis labels,
158160
and titles is independent of original location of axes. This is
159-
often True, but there are rare cases it is not.
161+
often true, but there are rare cases where it is not.
160162

161163
* pad=0 clips some of the texts by a few pixels. This may be a bug or
162164
a limitation of the current algorithm and it is not clear why it
@@ -169,7 +171,7 @@ Caveats
169171
Use with GridSpec
170172
-----------------
171173

172-
GridSpec has its own tight_layout method
174+
GridSpec has its own :func:`~matplotlib.gridspec.GridSpec.tight_layout` method
173175
(the pyplot api :func:`~matplotlib.pyplot.tight_layout` also works).
174176

175177
.. plot::
@@ -191,9 +193,9 @@ GridSpec has its own tight_layout method
191193
gs1.tight_layout(fig)
192194

193195

194-
You may provide an optional *rect* parameter, which specify the bbox
195-
that the subplots will be fit in. The coordinate must be in normalized
196-
figure coordinate and the default is (0, 0, 1, 1).
196+
You may provide an optional *rect* parameter, which specifies the bounding box
197+
that the subplots will be fit inside. The coordinates must be in normalized
198+
figure coordinates and the default is (0, 0, 1, 1).
197199

198200
.. plot::
199201
:include-source:
@@ -202,7 +204,7 @@ figure coordinate and the default is (0, 0, 1, 1).
202204
gs1.tight_layout(fig, rect=[0, 0, 0.5, 1])
203205

204206

205-
For example, this can be used for a figure with multiple grid_spec's.
207+
For example, this can be used for a figure with multiple gridspecs.
206208

207209
.. plot::
208210
:include-source:
@@ -230,13 +232,13 @@ We may try to match the top and bottom of two grids ::
230232
gs2.update(top=top, bottom=bottom)
231233
232234

233-
While this should be mostly good enough, but adjusting top and bottom
234-
may requires adjustment in hspace also. To update hspace & vspace, we
235-
call tight_layout again with updated rect argument. Note the rect
236-
argument specifies area including the ticklabels etc. Thus we will
237-
increase the bottom (which is 0 in normal case) by the difference
238-
between the *bottom* from above and bottom of each gridspec. Same
239-
thing for top.
235+
While this should be mostly good enough, adjusting top and bottom
236+
may require adjustment of hspace also. To update hspace & vspace, we
237+
call :func:`~matplotlib.gridspec.GridSpec.tight_layout` again with updated
238+
rect argument. Note that the rect argument specifies the area including the
239+
ticklabels, etc. Thus, we will increase the bottom (which is 0 for the normal
240+
case) by the difference between the *bottom* from above and the bottom of each
241+
gridspec. Same thing for the top.
240242

241243
.. plot::
242244
:include-source:
@@ -256,7 +258,7 @@ thing for top.
256258
Use with AxesGrid1
257259
------------------
258260

259-
While limited, axes_grid1 toolkit is also supported.
261+
While limited, the axes_grid1 toolkit is also supported.
260262

261263

262264
.. plot::
@@ -282,8 +284,8 @@ While limited, axes_grid1 toolkit is also supported.
282284
Colorbar
283285
--------
284286

285-
If you create colorbar with :func:`~matplotlib.pyplot.colorbar`
286-
command, the created colorbar is an instance of Axes not Subplot, thus
287+
If you create a colorbar with the :func:`~matplotlib.pyplot.colorbar`
288+
command, the created colorbar is an instance of Axes, *not* Subplot, so
287289
tight_layout does not work. With Matplotlib v1.1, you may create a
288290
colobar as a subplot using the gridspec.
289291

0 commit comments

Comments
 (0)