Skip to content

Commit d01ab8c

Browse files
committed
modify tight_layout section of what's new to include a demo
1 parent 773a7e6 commit d01ab8c

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

doc/users/whats_new.rst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,38 @@ A frequent issue raised by users of matplotlib is the lack of a layout
3535
engine to nicely space out elements of the plots. While matplotlib still
3636
adheres to the philosphy of giving users complete control over the placement
3737
of plot elements, Jae-Joon Lee created the :mod:`~matplotlib.tight_layout`
38-
module to address the most common layout issues.
38+
module and introduced a new
39+
command :func:`~matplotlib.pyplot.tight_layout`
40+
to address the most common layout issues.
3941

40-
:mod:`~matplotlib.tight_layout` will adjust the spacing between subplots
42+
.. plot::
43+
44+
plt.rcParams['savefig.facecolor'] = "0.8"
45+
plt.rcParams['figure.figsize'] = 4, 3
46+
47+
fig, axes_list = plt.subplots(2, 1)
48+
for ax in axes_list.flat:
49+
ax.set(xlabel="x-label", ylabel="y-label", title="before tight_layout")
50+
ax.locator_params(nbins=3)
51+
52+
plt.show()
53+
54+
plt.rcParams['savefig.facecolor'] = "0.8"
55+
plt.rcParams['figure.figsize'] = 4, 3
56+
57+
fig, axes_list = plt.subplots(2, 1)
58+
for ax in axes_list.flat:
59+
ax.set(xlabel="x-label", ylabel="y-label", title="after tight_layout")
60+
ax.locator_params(nbins=3)
61+
62+
plt.tight_layout()
63+
plt.show()
64+
65+
The usage of this functionality can be as simple as ::
66+
67+
plt.tight_layout()
68+
69+
and it will adjust the spacing between subplots
4170
so that the axis labels do not overlap with neighboring subplots. A
4271
:ref:`plotting-guide-tight-layout` has been created to show how to use
4372
this new tool.

0 commit comments

Comments
 (0)