For most new Matplotlib figures, use layout="constrained": it is more flexible about making room for supported labels, legends, colorbars, and complex subplot arrangements. Use tight_layout() when a simple existing figure needs a one-time spacing adjustment with direct padding controls. Do not call tight_layout() after enabling constrained layout; it turns that layout engine off.
How the two layout options differ
| Aspect | Constrained layout | Tight layout |
|---|---|---|
| How it works | Runs as the figure is drawn and adjusts axes to make room for supported decorations. | Directly adjusts spacing around subplots. |
| Best fit | Figures with colorbars, nested subfigures, axes spanning rows or columns, or mosaic layouts. | Simpler figures where a spacing adjustment is sufficient. |
| Padding controls | h_pad and w_pad are in inches; hspace and wspace are fractions of figure size. It also supports a normalized rect and a compress option. |
pad, h_pad, and w_pad are fractions of the font size; rect is a normalized rectangle for the subplot area. |
| Engine status | The more modern built-in layout engine; generally gives better results, according to the Matplotlib layout-engine API. | Matplotlib’s first layout engine, as described in the layout-engine API. |
Matplotlib’s constrained-layout guide describes it as similar to tight layout but substantially more flexible. For simple fixed-aspect grids, constrained layout’s compressed option can reduce excess whitespace.
Use constrained layout for a new figure
Set the layout while creating the figure, before adding axes:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2, layout="constrained")
This is especially useful when the figure’s axes have associated colorbars, span multiple rows or columns, or sit in nested subfigures or a mosaic. The engine also tries to align spines across shared rows or columns. The guide documents an alternative global setting, rcParams['figure.constrained_layout.use'] = True.
Recommended Free Tools
#1 Best Overall
Use tight layout for a straightforward spacing adjustment
For an existing simple figure, call fig.tight_layout() to adjust padding between and around subplots:
fig.tight_layout()
The Figure.tight_layout API defines pad, h_pad, and w_pad as fractions of the font size, and rect as the normalized rectangle the subplot area should fit within. If an Axes artist such as a legend or annotation should not affect the bounding-box calculation, set artist.set_in_layout(False).
Rank #2
What to check when the layout still looks wrong
- Neither method guarantees correct placement for every custom artist. Constrained layout accounts for tick labels, axis labels, titles, and legends, but other artists can still clip or overlap.
- Artists positioned in Axes coordinates beyond the Axes boundary may produce unusual results. The constrained-layout guide suggests adding such an artist directly to the Figure.
- Different row and column geometries made with
pyplot.subplotcan produce poor constrained-layout results. - Font rendering differences between backends can cause small output differences. Inspect the rendered figure in the backend and format that matter to you.
- On backends with a toolbar, constrained layout is turned off for toolbar zoom and pan events.
Keep constrained layout stable after drawing
Constrained layout normally updates Axes positions on each draw. If positions should remain fixed after an initial draw—for example, because tick labels change during an animation—the guide shows disabling further updates with fig.set_layout_engine('none').
Do not combine the two methods
Calling tight_layout() after enabling constrained layout turns constrained layout off, as the official guide explicitly warns. Choose one approach for a figure rather than using tight layout as a final step on a constrained figure.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.




