Python 使用matplotlib为每个x轴值设置多个条形图

Python 使用matplotlib为每个x轴值设置多个条形图,python,pandas,matplotlib,Python,Pandas,Matplotlib,我试图在条形图中每次有2个条形。 X轴必须是时间,y轴必须是计数。 每次我都试图为每个id绘制两个条形图 Id Time Count 585 10 9 585 11 34 585 12 96 193 10 147 193 11 85 193 12 1 尝试使用以下代码,但无法获得所需的结果。任何帮助都会很有帮助 提前谢谢 y = df1['Id'] z = df1['Count'] ax = plt.subpl

我试图在条形图中每次有2个条形。 X轴必须是时间,y轴必须是计数。 每次我都试图为每个id绘制两个条形图

  Id    Time Count
  585   10  9
  585   11  34
  585   12  96
  193   10  147
  193   11  85
  193   12  1
尝试使用以下代码,但无法获得所需的结果。任何帮助都会很有帮助

提前谢谢

  y = df1['Id']
  z = df1['Count']

  ax = plt.subplot(111)
  ax.bar(y, z,width=0.2,color='b',align='center')
  ax.bar(y, z,width=0.2,color='g',align='center')
  ax.xaxis_date()

  plt.show()

设置索引
+
取消堆栈

df.set_index(['Time', 'Id']).Count.unstack().plot.bar()

这次使用
Count
作为
ylabel

ax = df.set_index(['Time', 'Id']).Count.unstack().plot.bar()
ax.set_ylabel('Count')