0

I create a figure with multiple subplots. The figure has its title and each subplot has its respective title. The figure title uses plt.suptitle('Test',size=20). In the generated figure, shown as follows, the figure title and titles for the first subplot overlap with each other. How to solve this issue.

The major code for generating the related figure is as follows, and the details are comments out.

plt.figure(figsize=(6*1, 4*6))
for i in range(6):
    plt.subplot(6,1,i+1)
    # the code for plotting the data are skipped
    plt.title('title for subplots',size=10)
plt.suptitle('Test',size=20)

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
user297850
  • 7,705
  • 17
  • 54
  • 76
  • Often, `plt.tight_layout()` helps for these situations. – JohanC Apr 12 '22 at 21:34
  • @johanC, I had plt.tight_layout(), but it does not impact the result. – user297850 Apr 12 '22 at 22:31
  • Well, if you used it, it really helps to show it in the code. It has quite a large influence. You could try `plt.subplots_adjust(top=0.95)` after `plt.tight_layout()` to have more space. I am not sure why `tight_layout` doesn't work well here. In [Matplotlib tight_layout() doesn't take into account figure suptitle(https://stackoverflow.com/questions/8248467/matplotlib-tight-layout-doesnt-take-into-account-figure-suptitle) someone suggests to use constrained layout, as in `fig, axs = plt.subplots(6,1,figsize=(6*1, 4*6), constrained_layout=True)` – JohanC Apr 12 '22 at 23:04

0 Answers0