Matplotlib constrained_layout vs. tight_layout

If Matplotlib “suptitle” clashes with other figure text when using tight_layout() try constrained_layout, which can work better than tight_layout(). To make figures with subplots and suptitle work better, use figure(constrained_layout=True):

from matplotlib.figure import Figure

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

for i in range(3):
    ax[i].plot(range(5+5*i))

fg.suptitle('lots of lines')

fg.savefig("example.png")

This plot is often superior to fg.tight_layout()