Matplotlib constrained_layout vs. 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.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 much superior to fg.tight_layout()