Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →For a conventional Matplotlib subplot grid, call fig.tight_layout() after adding titles and axis labels. It adjusts subplot spacing when called so common decorations fit within the figure. For more complex layouts involving colorbars, legends, nested subfigures, or axes that span rows or columns, enable constrained layout when creating the figure instead.
Fix overlapping labels with tight_layout()
Call fig.tight_layout() after creating the axes and setting their titles and labels, but before displaying or saving the figure:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2)
for ax in axs.flat:
ax.set_xlabel("X label")
ax.set_ylabel("Y label")
ax.set_title("Panel title")
fig.tight_layout()
plt.show()
The function adjusts subplot parameters at the time you call it. Matplotlib’s tight-layout guide describes its scope as tick labels, axis labels, and titles. If you change labels or titles after calling it, call it again to recalculate the spacing.
When to use constrained layout instead
For a new figure with more involved decorations or grid geometry, try constrained layout from figure creation:
#1 Best Overall
fig, axs = plt.subplots(2, 2, layout="constrained")
The constrained-layout guide documents automatic adjustment for decorations including tick labels, legends, and colorbars. It is more flexible for colorbars shared across multiple axes, nested subfigures, and axes spanning rows or columns. Matplotlib’s layout-engine API describes constrained layout as the more modern built-in engine and generally better performing than tight layout.
Enable constrained layout before adding axes. Do not call tight_layout() afterward: doing so turns constrained layout off.
Rank #2
Choose a layout method for your figure
| Method | When it adjusts | Documented scope and fit |
|---|---|---|
fig.tight_layout() |
When called | Tick labels, axis labels, and titles; a practical one-time adjustment for conventional subplot grids. Matplotlib’s tight-layout guide documents this scope. |
| Constrained layout | Enabled when the figure is created and adjusts layout automatically | Broader decorations such as legends and colorbars, including more complex grids. See Matplotlib’s constrained-layout guide. |
fig.set_tight_layout(True) or rcParams["figure.autolayout"] = True |
On each redraw | Options documented by the tight-layout guide when repeated tight-layout adjustment is wanted. |
fig.subplots_adjust(...) |
When called | Manual subplot positioning for precise margin control; documented as an alternative in the tight-layout guide. |
If labels still overlap
Automatic layout is not a guarantee against every collision, particularly with custom artists or unusually long text. After rendering, try the adjustment best suited to the cause:
- Increase the figure size if the panels have too little room.
- Shorten or rotate long tick labels, or revise lengthy axis labels and titles.
- Use
fig.subplots_adjust(...)when a specific margin needs manual control. - For colorbars, legends, nested subfigures, or spanning axes, use constrained layout from figure creation and inspect the result.
The tight-layout guide is version 3.6.2 documentation; the cited constrained-layout guide and layout-engine API are from Matplotlib 3.11.2 stable documentation. The methods’ documented capabilities help guide the choice, but the rendered result depends on the figure and its artists.
Recommended Free Tools
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




