@@ -35,9 +35,38 @@ A frequent issue raised by users of matplotlib is the lack of a layout
35
35
engine to nicely space out elements of the plots. While matplotlib still
36
36
adheres to the philosphy of giving users complete control over the placement
37
37
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.
39
41
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
41
70
so that the axis labels do not overlap with neighboring subplots. A
42
71
:ref: `plotting-guide-tight-layout ` has been created to show how to use
43
72
this new tool.
0 commit comments