Pandas: set different ylim and titles for different subplots

☆樱花仙子☆ 提交于 2019-12-10 09:35:18

问题


Say I have this dataframe:

    Type       Cat1       Cat2       Cat3
0   A      0.384000   0.393000   0.458000
1   B      0.603337   0.381470   0.299773
2   C      0.585797   0.452570   0.317607
3   D      0.324715   0.765212   0.717755

That I plot like this (from here):

axes = df.set_index('Type').plot.bar(subplots=True, legend=False)
plt.subplots_adjust(hspace=0.35)

My problem: how can I set a different ylim for each subplot? And how can I modify things like the font size of the Cat titles?


回答1:


the plotting method returns an array of axes in your axes variable. You can access each one and set the title and ylim.

axes = df.set_index('Type').plot.bar(subplots=True, legend=False)
plt.subplots_adjust(hspace=0.35)
axes[0].set_ylim(0, 1.1)
axes[0].set_title('hello')



来源:https://stackoverflow.com/questions/40807091/pandas-set-different-ylim-and-titles-for-different-subplots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!