I am trying to add data labels on a bar chart, my dataframe is the following:
I tried several things and I got very close, but the graph also shows the index of my dataframe on top of the bar and I just need the data value. Also, I would like to increase the data value a little bit.
It shows the index labels besides the data values
My code is the following:
import matplotlib as mpl
import matplotlib.pyplot as plt
ax = df_final.plot(kind='bar',figsize=(20,8), width=0.8, color=['#5cb85c', '#5bc0de', '#d9534f'])
# Set legend size
ax.legend(fontsize=14)
# Set ticks sizes
ax.set_yticks([])
ax.tick_params(axis='x', labelsize=14)
# Set title and size
ax.set_title('Percentage of respondets interested in Data Science areas', fontsize=16)
# Remove borders
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
# Display percentage above bar graph
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', xytext=(0, 10), textcoords='offset points')
I really appreciate the help!