【问题标题】:How to change rotation of xticks in matplotlib?如何在 matplotlib 中更改 xticks 的旋转?
【发布时间】:2018-12-14 14:41:50
【问题描述】:

我想改变 xticks 的旋转,但我以 x AND yticks 旋转结束。我怎样才能只旋转 xticks?

这是我的代码:

# Plot mit Sidestepped 0/1

sns.set(style="darkgrid")

fig, ax = plt.subplots(1,2, figsize=(14,5))

for i in range(len(ax)):
    ax[i].tick_params(labelsize=15)
    ax[i].set_xlabel('label', fontsize=17, position=(.5,20))
    ax[i].set_ylabel('label', fontsize=17)

sns.countplot(x="page_name", hue="successful", data=mainDf, ax=ax[0]); 
sns.countplot(x="industry", hue="successful", data=mainDf, ax=ax[1]);

fig.suptitle('Categorical Features Count', position=(.5,1.1), fontsize=20)
ax[0].set_title('Type by Industry', fontsize=18)
ax[0].set_xlabel('Industry')
ax[0].tick_params(rotation=50)
ax[1].set_title('Success by Industry',  fontsize=18)
ax[1].set_xlabel('Industry')
fig.tight_layout()

fig.show()

这就是我得到的(x 但不幸的是 yticks 也旋转了!只看 ax[0] 处的左侧图!我只想旋转左侧图的 xticks!):

【问题讨论】:

  • ax[0].tick_params(axis="x", rotation=50)?
  • 谢谢!有效!这么愚蠢的问题,对不起你的时间。你可以回答,我会接受的。

标签: python matplotlib plot


【解决方案1】:

您可以使用tick_paramsaxis 参数来指定特定轴的旋转:

ax[0].tick_params(axis="x", rotation=50)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 2022-01-26
    • 2023-01-07
    • 2011-10-06
    • 2018-01-24
    • 1970-01-01
    • 2014-12-27
    相关资源
    最近更新 更多