📜  用结果数字绘制条形图 python - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:49.632000             🧑  作者: Mango

代码示例1
#If you want to just label the data points above the bar, you could use plt.annotate()
import numpy as np
import matplotlib.pyplot as plt

n = [1,2,3,4,5,]
s = [i**2 for i in n]
line = plt.bar(n,s)
plt.xlabel('Number')
plt.ylabel("Square")

for i in range(len(s)):
    plt.annotate(str(s[i]), xy=(n[i],s[i]), ha='center', va='bottom')

plt.show()