Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Use tight_layout() to adjust spacing between Matplotlib subplots and their labels; use bbox_inches="tight" when saving to trim excess space around the figure. They solve different problems and can be used together. For complex layouts, Matplotlib’s current guide generally favors constrained layout instead.
What each option does
| Option | What it changes | When it helps |
|---|---|---|
fig.tight_layout() |
Adjusts subplot parameters, including spacing and margins, so Axes decorations fit more cleanly within the figure. It is a layout adjustment, not an export crop. Matplotlib Tight layout guide | Use it when neighboring subplots, axis labels, tick labels, or titles are crowded or overlap. |
bbox_inches="tight" |
In savefig(), calculates a tight bounding box and saves that portion of the figure. It changes the saved output bounds, not subplot geometry. Matplotlib savefig API |
Use it when the exported image or vector graphic has too much whitespace around the plotted content. |
pad_inches |
Adds padding around the tight saved bounding box; the documented default is 0.1 inches. Matplotlib savefig API | Adjust it when you want more or less breathing room around the saved figure. |
Use both in a basic save workflow
First create and label the plot, then adjust its subplot layout and save with a tight output boundary:
As an Amazon Associate I earn from qualifying purchases.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [2, 1, 4])
ax.set_xlabel("X value")
ax.set_ylabel("Y value")
ax.set_title("Example")
fig.tight_layout() # Adjust subplot spacing and margins
fig.savefig("plot.png", bbox_inches="tight", pad_inches=0.1)
fig.tight_layout() operates on that figure. The equivalent plt.tight_layout() adjusts the current figure. The call applies the adjustment when it runs; for automatic adjustment on redraw, Matplotlib documents fig.set_tight_layout(True) and rcParams["figure.autolayout"] = True. Matplotlib Tight layout guide
Choose a layout method for complex figures
For colorbars, nested layouts, Axes spanning rows or columns, and alignment across a more complicated grid, Matplotlib’s current guide describes constrained layout as more flexible than tight_layout(). Enable it when creating the figure:
#1 Best Overall
fig, ax = plt.subplots(layout="constrained")
Choose one layout engine deliberately. Calling tight_layout() disables constrained layout, so do not call it if you want constrained layout to remain active. Matplotlib Constrained layout guide
Troubleshoot clipped labels and legends
Check whether an artist is included
If a label, legend, or other decoration is still clipped, check whether that artist participates in layout and tight-bounding-box calculations. Artist.set_in_layout(bool) controls its inclusion; excluding an artist can cause it to be cropped. The constrained-layout guide describes a more involved legend workflow that toggles inclusion and triggers a draw before saving. Matplotlib Artist.set_in_layout reference Matplotlib Constrained layout guide
Rank #2
Keep some padding
For a tight saved bounding box, pad_inches controls the extra margin. Although the documented default is 0.1 inches, the tight-layout guide warns that pad=0 can clip text by a few pixels and recommends padding greater than 0.3 for that layout adjustment. Matplotlib Tight layout guide Matplotlib savefig API
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesDo not rely on repeated calls to converge
tight_layout() estimates space from artist extents such as tick labels, axis labels, and titles. Its assumption that the extra space needed is independent of an Axes’ original position can fail in rare cases, and repeated calls may produce small variations because the algorithm does not necessarily converge. Matplotlib Tight layout guide
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.




