And I would like to annotate each bar as follow :
The code for the bar graph is the following :
xs = sumAgent['Year'].values
ys = sumAgent['agentCom'].values
plt.barh(xs,ys)
I have a list of strings : lst = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
I would like to annotate my bars with the following strings (first element of the list = annotation of first bar).
for x,y in zip(xs,ys):
label = "{:.2f}".format(y)
plt.annotate('A', # this is the text
(x,y), # this is the point to label
textcoords="offset points", # how to position the text
xytext=(0,10), # distance from text to points (x,y)
ha='center') # horizontal alignment can be left, right or center
But of course it will annotate all bars with value A and the position is not inside the bar graph.
Any ideas on how I could resolve this ?