python - How to display the value of the bar on each bar with pyplot.barh()? -


i generated bar plot, how can display value of bar on each bar?

current plot:

enter image description here

what trying get:

enter image description here

my code:

import os import numpy np import matplotlib.pyplot plt  x = [u'info', u'cuisine', u'type_of_place', u'drink', u'place', u'meal_time', u'dish', u'neighbourhood'] y = [160, 167, 137, 18, 120, 36, 155, 130]  fig, ax = plt.subplots()     width = 0.75 # width of bars  ind = np.arange(len(y))  # x locations groups ax.barh(ind, y, width, color="blue") ax.set_yticks(ind+width/2) ax.set_yticklabels(x, minor=false) plt.title('title') plt.xlabel('x') plt.ylabel('y')       #plt.show() plt.savefig(os.path.join('test.png'), dpi=300, format='png', bbox_inches='tight') # use format='svg' or 'pdf' vectorial pictures 

add:

for i, v in enumerate(y):     ax.text(v + 3, + .25, str(v), color='blue', fontweight='bold') 

result:

enter image description here

the y-values v both x-location , string values ax.text, , conveniently barplot has metric of 1 each bar, enumeration i y-location.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -