【问题标题】:How can I determine the position of my subplot label?如何确定子图标签的位置?
【发布时间】:2021-07-26 05:29:13
【问题描述】:

我正在尝试使用 Python 标记我的两个子图并将文本定位到右上角:

fig, axs = plt.subplots(2, sharex=True, figsize = (16,18))
plt.xticks(fontsize=15)
...
axs[0].text(0.9,0.1,r'$E_b$',verticalalignment='top',fontsize = 30)

最后一行引用自 matplotlib.axes.Axes.text 。我已经阅读了一些示例,但我仍然不太确定如何确定 x 和 y 的适当值以使我的标签位于右上角?当前值(0,9 和 0.1)不起作用。

【问题讨论】:

    标签: python matplotlib subplot


    【解决方案1】:

    这样做:

    fig, axs = plt.subplots(2, sharex=True, figsize = (16,18))
    plt.xticks(fontsize=15)
    
    plt.text(0.67, 0.9, 'I am 0.70, 0.90', fontsize=14, transform=plt.gcf().transFigure)
    plt.text(0.67, 0.48, 'I am 0.70, 0.48', fontsize=14, transform=plt.gcf().transFigure)
    

    会给你这个:

    axs[0].text(...)
    

    将为您提供相对于 axs[0] 的文本坐标。我想你想要的是图形坐标而不是轴坐标。为此,您需要

    transform=plt.gcf().transFigure
    

    只需plt.text(...),因此您无需指定子图。

    图形坐标0,0在左下角,1,1在右上角。

    【讨论】:

      猜你喜欢
      • 2022-10-21
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多