0

I've a data set similar to this as follow:

data={'Subject':['English','Maths','Chemistry'],'Very Interested':[24,20,17],'Somewhat interested':[15,19,12],'Not interested':[18,24,19]}
da=pd.DataFrame(data)
da.set_index('Subject',inplace=True)
ax=da.plot(kind='bar', figsize=(20, 8), color=['#5cb85c','#5bc0de','#d9534f'],width=0.8)
ax.set_xlabel('Subjects',fontsize=14)
ax.set_ylabel('Responses',fontsize=14) 
ax.set_title('Interest of students in subjects',fontsize=16)

I just want the response of students to come at the top of bars in the bar chart. I've tried similar threads but I'm unable to mix it with my product.I have been trying to for 8 hours but still I've no clue. Would someoene please help me with it. enter image description here

  • 1
    Did you look at the matplotlib documentation, specifically [Grouped bar chart with labels](https://matplotlib.org/gallery/lines_bars_and_markers/barchart.html)? – ImportanceOfBeingErnest Nov 17 '19 at 20:01
  • 1
    Duplicate: https://stackoverflow.com/questions/25447700/annotate-bars-with-values-on-pandas-bar-plots – Yash Kant Nov 17 '19 at 20:08

1 Answers1

0

Thanks Yash Kant, it worked. Just adding the following code:

for p in ax.patches: 
    ax.annotate(np.round(p.get_height(),decimals=2), 
    (p.get_x()+p.get_width()/2., p.get_height()), 
    ha='center', va='center', xytext=(0, 10), 
    textcoords='offset points')