ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))
ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))

def autolabel(rects):
    """
    Attach a text label above each bar displaying its height
    """
for rect in rects:
    height = rect.get_height()
ax.text(rect.get_x() + rect.get_width() / 2.0, 1.05 * height, '%d' % int(
    height), ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()
How to display the value of the bar on each bar with pyplot.barh()?