海底子图X轴标签不旋转

发布于 2025-02-04 10:23:43 字数 618 浏览 3 评论 0原文

我正在尝试显示带有X轴标签的2个子图,旋转90度。出于某种原因,第一个子图标签没有旋转。谁能让我知道我缺少什么?谢谢!

fig, ax = plt.subplots(1, 2, sharey=True, figsize=(20,10))
fig.suptitle('Top and Bottom Countries by Rating')
plt.xticks(rotation=90)

sns.barplot(data=top_df, y='rating', x='bean_origin', ax=ax[0], palette="Blues_d")
ax[0].set_title('Top 10 Countries by Avg Rating')

sns.barplot(data=bottom_df, y='rating', x='bean_origin', ax=ax[1], palette="Reds_d")
ax[1].set_title('Bottom 10 Countries by Avg Rating')

plt.show()

链接到图表图像

I'm trying to show 2 subplots with x-axis labels rotated 90 degrees. The first subplot's labels for some reason are not rotating. Can anyone let me know what I'm missing? Thanks!

fig, ax = plt.subplots(1, 2, sharey=True, figsize=(20,10))
fig.suptitle('Top and Bottom Countries by Rating')
plt.xticks(rotation=90)

sns.barplot(data=top_df, y='rating', x='bean_origin', ax=ax[0], palette="Blues_d")
ax[0].set_title('Top 10 Countries by Avg Rating')

sns.barplot(data=bottom_df, y='rating', x='bean_origin', ax=ax[1], palette="Reds_d")
ax[1].set_title('Bottom 10 Countries by Avg Rating')

plt.show()

Link to chart image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一生独一 2025-02-11 10:23:43

尝试一下:

1。绘制之后致电:如果1次不够,则在每个绘图后尝试添加它,

sns.barplot('BLA BLA')
plt.xticks(rotation=90)

否则请在下面尝试以下一个解决方案:

2。

fig.autofmt_xdate(rotation=90)

3。

labels = ['One', 'Two', 'Three'] #your labels
ax.set_xticks([1, 2, 3]) #your coord
ax.set_xticklabels(labels, rotation=90)

<强> 4。

ax.tick_params(axis='x', labelrotation=90)

如果上面没有可行的代码。

注意: imo,45°更好:)

Try this:

1. Call this AFTER plotting: if 1 time not enough, try to add it after each plotting

sns.barplot('BLA BLA')
plt.xticks(rotation=90)

Otherwise try one of these solutions below:

2. :

fig.autofmt_xdate(rotation=90)

3.

labels = ['One', 'Two', 'Three'] #your labels
ax.set_xticks([1, 2, 3]) #your coord
ax.set_xticklabels(labels, rotation=90)

4.

ax.tick_params(axis='x', labelrotation=90)

If none above works, provide full code.

Note: IMO, 45° is better :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文