答案 0 :(得分:2)
我希望这个简单的例子可以帮到你:
import numpy as np
import matplotlib.pyplot as plt
N = 5
values = (5, 7, 4, 9, 2)
ind = np.arange(N)
width = 0.35
fig, ax = plt.subplots()
rects1 = ax.bar(ind, values, width, color='r')
# add some text for labels, title and axes ticks
ax.set_ylabel('Y-label')
ax.set_title('X-label')
ax.set_xticks(ind + width)
ax.set_xticklabels(('1', '2', '3', '4', '5'))
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects1)
plt.show()
答案 1 :(得分:2)