Matplotlib tight_layout() doesn't take into account figure suptitle

后端 未结 10 1592
既然无缘
既然无缘 2020-11-28 18:02

If I add a subtitle to my matplotlib figure it gets overlaid by the subplot\'s titles. Does anybody know how to easily take care of that? I tried the tight_layout()

10条回答
  •  佛祖请我去吃肉
    2020-11-28 18:32

    You could manually adjust the spacing using plt.subplots_adjust(top=0.85):

    import numpy as np
    import matplotlib.pyplot as plt
    
    f = np.random.random(100)
    g = np.random.random(100)
    fig = plt.figure()
    fig.suptitle('Long Suptitle', fontsize=24)
    plt.subplot(121)
    plt.plot(f)
    plt.title('Very Long Title 1', fontsize=20)
    plt.subplot(122)
    plt.plot(g)
    plt.title('Very Long Title 2', fontsize=20)
    plt.subplots_adjust(top=0.85)
    plt.show()
    

提交回复
热议问题