Thursday, 15 July 2010

python - How can I display text over columns in a bar chart in matplotlib? -


I have a bar and I want to show some text on each column, how can I do this?

I believe this will tell you in the right direction:

> The part you are most interested in is:

def autolabel (rects): rect in rect: height = rect.get_height () plt.text ( Rect.get_x () + rect .get_width () / 2., 1.05 * height, '% d'% int (height), ha = 'center', va = 'bottom') < P> The placement of text is determined by the height function, or the height of the column, and the number to be placed at the top of each column: '% d'% int (height) is written by. So whatever you have to do is make an array of stars named 'Naam', which you want at the top of the column and repeat it again. Be sure to change the format for the string (% s) and double not. Def autolabel (rects): attach some text labels for # ii, enqueue in rect (rects): height = rect.get_height () plt.text (rect.get_x) + Rect.get_width () / 2., 1.02 * height, '% s'% (name [ii]), ha = 'center', va = 'bottom') autolabel (rects1)

It should!


No comments:

Post a Comment