import numpy as np
import 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
时间: 2024-10-31 15:24:23