gpt4 book ai didi

python - 添加第二个 x_axis 覆盖标题

转载 作者:太空宇宙 更新时间:2023-11-03 15:06:52 25 4
gpt4 key购买 nike

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

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 窗口内

最佳答案

由于您的标题适用于整个图形而不仅仅是子图,@György Solymosi 的回答可能是可行的方法(而不是添加新行,这是一种 hack)。

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

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

关于python - 添加第二个 x_axis 覆盖标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31655032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com