import numpy as np
import matplotlib.pyplot as plt
# 绘制班级同学体重的分布规律直方图
# 1、创建画布
plt.figure()
# 2、绘图
# 假设咱们有20个同学
weight = np.array([40,44,48,46,51,56,58,62,69,75,89,78,69,56,88,57,49,60,50,61])
# bins = 4 让系统默认进行分组
# 可以自定义进行分组--等宽分组
# 计算最大值与最小值差值---极差
ptp = weight.max()- weight.min()
# 计算步长 并向上取整
step = np.ceil( ptp / 4)
# 设置等宽bins
bins = np.arange(weight.min(),weight.max()+ step,step)
# print(bins)
plt.hist(weight,bins=bins,color='r',edgecolor='g')
# 设置x刻度
plt.xticks(bins)
# 增加网格曲线
plt.grid(True,axis='y',alpha=0.2)
# 不需要设置图例
# 3、展示图片
plt.show()
# 统计薪资分布的直方图
# 大家自己创建数据 [3000,20000]之间,创建25个人,自定义分组,去查看薪资分布情况
# 需要写出结论
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交