Get the title of a given figure

后端 未结 3 1140
梦如初夏
梦如初夏 2020-12-20 19:32

I have created a figure and have attached to it a title like this:

def func():
    fig = plt.figure()
    fig.suptitle(\"my title\")
    return fig


        
相关标签:
3条回答
  • 2020-12-20 20:06

    Another solution would be to use fig.texts which returns a list of matplotlib.text.Text objects. Therefore, we can get the first element of the list, then use get_text() to get the actual title:

    fig = plt.figure()
    fig.suptitle("my title")
    
    text = fig.texts[0].get_text()
    print(text)
    # my title
    
    0 讨论(0)
  • 2020-12-20 20:11

    There seems to be no public API to access this. But with some cautions you could use the non-public / potentially instable members:

    fig._suptitle.get_text()
    
    0 讨论(0)
  • 2020-12-20 20:18

    You can get the title through the axes:

    fig.axes[0].get_title()
    

    In case you have access to the axis itself, you can directly do:

    ax.get_title()
    
    0 讨论(0)
提交回复
热议问题