plt.hist()添加数据标注

import seaborn as sns
# 预设风格
from matplotlib.pylab import style #自定义图表风格
style.use('ggplot')
sns.set(font_scale=1.5, font = 'SimHei')  # 设置字号大小、字体(这里是黑体),预防汉字不显示

plt.figure(figsize=(20, 15))
# 添加总标题
plt.suptitle('残差分布图', x=0.5, y=0.92, fontsize=22, color='k')
# 设置子图间距
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.3, hspace=0.5)
for i in range(dfA.shape[1]):
    plt.subplot(4,3,i+1)
     
    n, bins, patches = plt.hist(dfA.iloc[:, i], bins=10, color="blue",edgecolor="black",density=False)#直方图
    plt.xlabel(dfA.columns[i])
    plt.ylabel('频数')
    for i in range(len(n)):
        plt.text((bins[i]+bins[i+1])/2, n[i]*1.04, int(n[i]), color = 'red', fontsize=16, horizontalalignment="center")  
 
plt.show();

 

你可能感兴趣的:(python,python)