在ti上添加第二个x_轴写入

2024-09-27 00:15:34 发布

您现在位置:Python中文网/ 问答频道 /正文

如何移动子地块的标题,使第二个轴不在标题的顶部,而是在标题的下方?这是它的样子

enter image description here

下面是相关的代码片段:

    # fig is a subplotAxes object
    fig.set_ylabel('Altitude (km)')
    fig.set_xlabel('Time')   
    fig.get_xaxis().set_major_formatter(mpl.dates.DateFormatter('%H:%M:%S'))

    cbar_label = 'Total Attenuated Backscatter 532nm (km$^{-1}$ sr$^{-1}$)'
    cbar = pfig.colorbar(im)
    cbar.set_label(cbar_label)

    # create second axis
    ax2 = fig.twiny()
    ax2.set_label('Latitude')
    ax2.set_xlim(latitude[0], latitude[-1])

    # set title, but title is overwritten
    fig.set_title("Averaged 532 nm Total Attenuated Backscatter")

我不知道这是否是我的身材大小或一个简单的格式错误的原因。我不想扩大我的图形大小,因为这个图位于Tkinter窗口内


Tags: 标题titleisfiglabeltotalsetlatitude
3条回答

试试fig.suptitle("Averaged 532 nm Total Attenuated Backscatter")

这个解决方案比我想象的要简单得多,我觉得自己很笨。我所需要做的就是在标题的末尾添加一个\n

 fig.set_title("Averaged 532 nm Total Attenuated Backscatter\n")

enter image description here

由于您的标题适用于整个人物,而不仅仅是子情节,@György Solymosi的答案可能是正确的(而不是添加一行新词,这是一种攻击)

或者,您可以将标题文本重新定位到您想要的位置,例如,将其提高5%:

title = fig.set_title("Flying monkey density")
title_xy = title.get_position()
title.set_position([title_xy[0], title_xy[1]*1.05])

相关问题 更多 >

    热门问题