Reputation: 125
I have the following dataframe:
my_df = pd.DataFrame(data={'Year': ['2017','2018','2019','2019','2019','2019','2020','2020'],
'Threshold':[96, 91, 20.59, 47.37, 78.12, 10.00, 15.00 ,91],
'Fee' : ["No","No", "20%", "20%", "5%", "20%", "20%", "No"]})
I am using seaborn to plot it:
palette={"No": "g","20%": "y", "5%": "r"}
fig,ax = plt.subplots()
fig.set_size_inches(10,8)
sns.barplot(x="Year", y="Threshold",hue = 'Fee', palette = palette, data=my_df, ci=None)
for p in ax.patches:
ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width() / 2, p.get_height()),
ha='center', va='center', fontsize=11, color='black', xytext=(0, 10),
textcoords='offset points',fontweight='bold')
However, the displayed graph returns the average of the Threshold variable per Year and I want to show all 8 dataframe Thresholds on the graph.
How can I fix it?
Upvotes: 1
Views: 1817
Reputation: 36
Try this one:
my_df = pd.DataFrame(data={'Year': ['2017','2018','2019','2019','2019','2019','2020','2020'],
'Threshold':[96, 91, 20.59, 47.37, 78.12, 10.00, 15.00 ,91],
'Fee' : ["No","No", "20%", "20%", "5%", "20%", "20%", "No"]})
palette={"No": "g","20%": "y", "5%": "r"}
fig,ax = plt.subplots()
fig.set_size_inches(10,8)
g = sns.barplot(x=my_df.index, y="Threshold",hue = 'Fee', palette = palette, data=my_df, ci=None)
g.set(xticklabels=my_df['Year'])
for p in ax.patches:
ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width() / 2, p.get_height()),
ha='center', va='center', fontsize=11, color='black', xytext=(0, 10),
textcoords='offset points',fontweight='bold')
Upvotes: 1