美文网首页
python matplotlib用hist()方法绘制直方图

python matplotlib用hist()方法绘制直方图

作者: 米陽 | 来源:发表于2021-06-10 10:17 被阅读0次

import pandasas pd

import matplotlib.pyplotas plt

pd.set_option('display.width', 10000)

pd.set_option('display.max_columns', 2000)

pd.set_option('display.max_rows', 10000)

plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']

plt.rcParams['axes.unicode_minus'] =False

plt.figure(figsize=(15, 10))

df = pd.read_excel(r'D:\bigData\客户年龄统计表.xlsx')

x = df['年龄']

plt.hist(x, bins=9)

plt.xlim(15, 60)

plt.ylim(0, 40)

plt.title('年龄分布直方图', fontsize=20)

plt.xlabel('年龄')

plt.ylabel('人数')

# 这里设置直方图网格

plt.grid(b=True, linestyle='dotted', linewidth=1)

plt.show()

相关文章

网友评论

      本文标题:python matplotlib用hist()方法绘制直方图

      本文链接:https://www.haomeiwen.com/subject/krkleltx.html