【问题标题】:Multiple size font in suptitle字幕中的多种大小字体
【发布时间】:2018-05-22 18:15:24
【问题描述】:

我想在我的图表中有多个标题。图片胜过任何文字:

我为每个图表(D2/E、D3/E 和 D4/E)使用title,为标题 1 和 2 使用suptitle,但它们的字体大小相同。 Title 1 和 Title 2 有不同尺寸的解决方案吗?

我已经看到 this solution 使用 LaTeX,但问题是当我使用 plt.rc('text', usetex=True) 时,每个字体和文本都会更改。此外,我在每个标题中都使用了变量,看起来我不能用 LaTeX 做到这一点。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您可以使用matplotlib.pyplot.text 对象来获得相同的结果。请注意,您需要确保通过使用transform=fig.transFigure 参数来使用图形坐标系,并使用ha = "center" 设置水平对齐方式

    一个例子:

    import matplotlib.pyplot as plt
    
    fig, axes = plt.subplots(1,3)
    plt.text(x=0.5, y=0.94, s="My title 1", fontsize=18, ha="center", transform=fig.transFigure)
    plt.text(x=0.5, y=0.88, s= "My title 2 in different size", fontsize=12, ha="center", transform=fig.transFigure)
    
    for i, ax in enumerate(axes.flatten()):
        ax.set_title("D{}/E".format(i))
    
    plt.subplots_adjust(top=0.8, wspace=0.3)
    
    plt.show()
    

    【讨论】:

    • 我尝试了这个解决方案,但没有使用 'transform=fig.transFigure',效果不佳,非常感谢!
    猜你喜欢
    • 2021-11-23
    • 1970-01-01
    • 2021-07-31
    • 2012-05-27
    • 1970-01-01
    • 2023-03-22
    • 2011-06-13
    • 1970-01-01
    相关资源
    最近更新 更多