matplotlib直方图绘图并且标注数字

import matplotlib.pyplot as plt
from collections import defaultdict
m = defaultdict(int)
df = df.dropna()
for i in df['consume_level']:
    m[int(i)] +=1
print(m)
plt.bar(m.keys(),m.values())
for a,b in m.items():
    plt.text(a, b+0.05, '%.0f' % b, ha='center', va= 'bottom',fontsize=17)
plt.xticks(range(len(m.keys())))
plt.legend()
plt.show()

 

posted @ 2021-12-23 11:40  qiezi_online  阅读(904)  评论(0编辑  收藏  举报