import numpy as npimport matplotlib.pyplot as plt
# 生成测试数据x = np.linspace(0, 10, 11)y = 11-x
# 绘制柱状图plt.bar(x, y)# 循环,为每个柱形添加文本标注
# 居中对齐for xx, yy in zip(x,y): plt.text(xx, yy+0.1, str(yy), ha='center')
# 显示图形plt.show()
运行效果:
原文地址:http://www.python88.com/topic/3616