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()