且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

利用matplotlib和 pandas 制作分组图

更新时间:2023-02-06 20:59:13

iUC是否需要非堆叠条形图?

df_month.plot.bar()

输出:

使用您的代码:

您应该删除stacked=True(或使用stacked=False):

df_month = pd.DataFrame(dataavail, index=years)
fig, ax1 = plt.subplots(1, figsize=(8, 5))
df_month.plot(kind='bar', stacked=False, colormap=plt.cm.tab20, ax=ax1)
plt.legend(loc="upper right", ncol = 3,handlelength=1.5, borderpad=0.2, labelspacing=0.2) 
plt.xticks(rotation=0)
plt.show()