tryingtobeastoic
tryingtobeastoic

Reputation: 195

How can I plot a bar plot grouped by month and year using matpltlib.pyplot?

This is my code:

plt.bar(df.index, df['January'])
plt.bar(df.index, df['February'])

This is the figure that I get:

enter image description here

How can I get the orange and blue bars side-by-side?

Upvotes: 0

Views: 101

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150745

You can use Pandas' plotting function:

df.plot.bar(y=['January','February'])

Or manually align the bars:

width=0.4
plt.bar(df.index, df['January'], width=-width, align='edge')
plt.bar(df.index, df['February'], width=width, align='edge')

Upvotes: 1

Related Questions