Free tools Windows power users keep installed
One-click scans. No signup required.
tight_layout() does not take wspace or hspace. To set subplot gaps directly, use subplots_adjust(wspace=..., hspace=...). Use tight_layout() when you want Matplotlib to adjust padding around subplot labels and titles automatically; its spacing controls are pad, w_pad and h_pad.
Set subplot gaps with subplots_adjust
For explicit control over horizontal and vertical gaps, call subplots_adjust on the figure:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2)
fig.subplots_adjust(wspace=0.35, hspace=0.45)
You can also use the pyplot form, plt.subplots_adjust(wspace=0.35, hspace=0.45). These example values are starting points, not universal settings. Matplotlib defines wspace as a fraction of the average Axes width and hspace as a fraction of the average Axes height. See the Matplotlib subplots_adjust API.
Use tight_layout for automatic padding
tight_layout() adjusts subplot parameters to make room for labels, tick labels and titles. Its documented arguments include pad, w_pad, h_pad and rect—not wspace or hspace. The padding values are fractions of font size, and w_pad and h_pad default to pad. The optional rect is a tuple of (left, bottom, right, top) coordinates normalized to the figure.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
fig.tight_layout(pad=1.1, w_pad=0.8, h_pad=0.8)
The numbers in this example are illustrative. They are not equivalent to the same numeric values passed to subplots_adjust, because the APIs use different units and layout rules. For parameter details, see the Matplotlib tight_layout API.
Choose the layout method that fits your figure
| What you need | Use | How spacing is specified |
|---|---|---|
| Directly set gaps between subplots | subplots_adjust() |
wspace and hspace are fractions of average Axes width and height. |
| Automatically adjust padding for subplot labels and titles | tight_layout() |
pad, w_pad and h_pad are fractions of font size. |
| Let a layout engine coordinate the figure layout | Constrained layout | Uses its own spacing and padding controls; these do not share the units of tight_layout. |
For constrained layout, enable it when creating a figure with layout="constrained". Its wspace and hspace are distributed among the gaps as fractions of figure space; for example, with three columns, wspace=0.2 allocates 0.1 of figure width to each of the two gaps. The current layout-engine API lists defaults of 0.02 for both spacing settings and 0.04167 inches for each pad. Consult the Matplotlib layout-engine API for the engine’s behavior and controls.
Rank #2
Matplotlib describes constrained layout as more modern than tight layout and generally likely to give better results, but the better choice depends on the figure. The tight-layout guide also cautions that tight layout checks tick-label, axis-label and title extents and may not work in some cases. Neither approach should be assumed to handle every artist or custom layout.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Check your Matplotlib version
The linked stable references document Matplotlib 3.11.2 for tight_layout, subplots_adjust and the layout-engine API; the configuration reference is for 3.11.0. If you use another release, check its documentation for the available arguments and defaults.
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.




