gpt4 book ai didi

python - 在子图中旋转刻度标签(Pyplot、Matplotlib、gridspec)

转载 作者:太空狗 更新时间:2023-10-30 00:29:32 25 4
gpt4 key购买 nike

我正在尝试将子图(使用 GridSpec 创建)的 x 标签旋转 45 度。我试过使用 axa.set_xticks()axa.set_xticklabels,但它似乎不起作用。谷歌也没有帮助,因为大多数关于标签的问题都是关于正常情节,而不是次要情节。

见下面的代码:

width = 20                                    # Width of the figure in centimeters
height = 15 # Height of the figure in centimeters
w = width * 0.393701 # Conversion to inches
h = height * 0.393701 # Conversion to inches

f1 = plt.figure(figsize=[w,h])
gs = gridspec.GridSpec(1, 7, width_ratios = [1.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])

axa = plt.subplot(gs[0])
axa.plot(dts, z,'k', alpha=0.75, lw=0.25)
#axa.set_title('...')
axa.set_ylabel('TVDSS ' + '$[m]$', fontsize = '10' )
axa.set_xlabel('slowness 'r'$[\mu s/m]$', fontsize = '10')
axa.set_ylim(245, 260)
axa.set_xlim(650, 700)
axa.tick_params(labelsize=7)
axa.invert_yaxis()
axa.grid()

任何帮助将不胜感激!

最佳答案

您可以通过多种方式做到这一点:

这是一个利用 tick_params 的解决方案:

ax.tick_params(labelrotation=45)

这是另一个利用 set_xticklabels 的解决方案:

ax.set_xticklabels(labels, rotation=45)

Here是利用 set_rotation 的第三种解决方案:

for tick in ax.get_xticklabels():
tick.set_rotation(45)

关于python - 在子图中旋转刻度标签(Pyplot、Matplotlib、gridspec),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31186019/

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