首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >共享和共享不为子图创建共享轴标签

共享和共享不为子图创建共享轴标签
EN

Stack Overflow用户
提问于 2019-05-13 17:40:25
回答 1查看 291关注 0票数 0

我的图表很好,我已经按照文档创建了共享的x和y标签,因为我想要一个更清晰的子图,但是传递给subplots()的参数不能正常工作。

代码:

代码语言:javascript
运行
复制
fig, axs = plt.subplots(3, 2, sharex=True, sharey=True, figsize=(10,10))

plt.subplot(3, 1, 1)
plt.title('20 highest paid app markets, april 4/4-4/10')
dd_404_410.groupby('market').period_paid_apps.mean().sort_values(ascending=False).nlargest(10).plot(kind='bar', color='darkgrey')
plt.ylabel('apps')
plt.xticks(rotation=45)

plt.subplot(3, 1, 2)
plt.title('20 highest paid app markets, april 4/11-4/17')
dd_411_417.groupby('market').period_paid_apps.mean().sort_values(ascending=False).nlargest(10).plot(kind='bar', color='darkgrey')
plt.ylabel('apps')
plt.xticks(rotation=45)

plt.subplot(3, 1, 3)
plt.title('20 highest paid app markets, april 4/18-4/26')
plt.ylabel('apps')
dd_418_426.groupby('market').period_paid_apps.mean().sort_values(ascending=False).nlargest(10).plot(kind='bar', color='darkgrey')
plt.xticks(rotation=45)

plt.tight_layout()
plt.show()

有没有人知道需要修复什么,以便我在x轴上有一个market标签,在y轴上有一个apps标签?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-13 20:23:54

实际上,您最初使用plt.subplots()创建了具有共享x和y的子图。但是,您要用连续的命令plt.subplot()覆盖轴(注意末尾缺少s)。

这是你应该做的方法(没有测试,因为我没有你的数据)

代码语言:javascript
运行
复制
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True, sharey=True, figsize=(10,10))

ax1.set_title('20 highest paid app markets, april 4/4-4/10')
ax1.set_ylabel('apps')
<YOUR DATAFRAME>.plot(kind='bar', color='darkgrey', ax=ax1)

ax2.set_title('20 highest paid app markets, april 4/11-4/17')
ax2.set_ylabel('apps')
<YOUR DATAFRAME>.plot(kind='bar', color='darkgrey', ax=ax2)

ax3.set_title('20 highest paid app markets, april 4/18-4/26')
ax3.set_ylabel('apps')
<YOUR DATAFRAME>.plot(kind='bar', color='darkgrey', ax=ax3)

plt.xticks(rotation=45)

plt.tight_layout()
plt.show()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56117378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档