Use Matplotlib constrained_layout instead of tight_layout

Many legacy tutorials and examples for Matplotlib use tight_layout(). Matplotlib 3.3.0 improved “suptitle” to no longer clash with other figure text when using tight_layout(). Matplotlib constrained_layout is still being improved and is often recommended over tight_layout().

To make figures with subplots and suptitle work better, use figure(constrained_layout=True):

from matplotlib.pyplot import figure, show

fg = figure(constrained_layout=True)
ax = fg.subplots(3, 1)

for i in range(3):

fg.suptitle('lots of lines')


This plot is much superior to fg.tight_layout()