1

I am trying to have 2 bars for each time in the bar chart. X axis has to be time and y axis has to be count. For each time I am trying to plot 2 bars for each id.

  Id    Time Count
  585   10  9
  585   11  34
  585   12  96
  193   10  147
  193   11  85
  193   12  1

Tried with the below code but could not get the desired results. Any help would be really helpful.

Thanks in advance !!

  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()

1 Answer 1

1

set_index + unstack

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

enter image description here

This time with Count as the ylabel

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.