I have below data,
Am trying to plot bar chart in matplotlib using below code,
pyplot.bar(gender, ward, width, color='orange')
pyplot.bar(count, gender, width, color='tomato')
My expectation is as below which is created in excel,
Any suggestion will be helpful to get the same in matplotlib
You could achieve that very easy withseaborn.barplot
.
import seaborn as sns
sns.barplot(data=df, x='Ward', y='Count', hue='Gender', palette=['orange', 'tomato']) #df is the dataframe you showed as example
Without seaborn, you could pivot your data before plotting it. Like this:
df.pivot(index='Ward', columns='Gender', values='Count').plot(kind='bar', color=['orange', 'tomato'])
plt.ylabel('Count')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.