我的图表很好,我已经按照文档创建了共享的x和y标签,因为我想要一个更清晰的子图,但是传递给subplots()
的参数不能正常工作。
代码:
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
标签?
发布于 2019-05-13 20:23:54
实际上,您最初使用plt.subplots()
创建了具有共享x和y的子图。但是,您要用连续的命令plt.subplot()
覆盖轴(注意末尾缺少s)。
这是你应该做的方法(没有测试,因为我没有你的数据)
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()
https://stackoverflow.com/questions/56117378
复制相似问题