Matplotlib placement of text e.g. suptitle inside the frame

后端 未结 2 1938
陌清茗
陌清茗 2021-02-05 04:01

So far i have placed my suptitles above the frame, like this:

\"enter

How can i ge

相关标签:
2条回答
  • 2021-02-05 04:41

    Have you considered axes.title? You can see the documentation for it here. You can also pass x and y coordinates as keyword arguments ax.title("my title", x=0.5, y=0.6).

    Hope this helps.

    0 讨论(0)
  • 2021-02-05 04:59

    Your solution using text is also my go-to solution. However, you don't need to compute the position based on xlim and ylim. If you set transform=ax.transAxes the coordinates for positioning the text are taken as being relative to the axes bounding box (0,0 being the lower left corner). Like so:

    data = range(1,10);
    fig = figure()
    for i in range(6):
        ax = fig.add_subplot(2,3,i)
    
        ax.text(.5,.9,'centered title',
            horizontalalignment='center',
            transform=ax.transAxes)
    
        ax.plot(data)
    show()
    

    Plot showing text relative to axes bounding box.

    Hope that helps!

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