代码拉取完成,页面将自动刷新
import matplotlib.pyplot as plt
import random
import matplotlib
# 设置matplotlib支持中文
font = {'family' : 'SimHei',
'weight' : 'bold',
'size' : '10'}
matplotlib.rc("font" , **font)
#####################################################################
#https://www.runoob.com/matplotlib/matplotlib-hist.html
#############################没有统计过的数据可以用hist来绘制直方图################################
# x=[]
# for i in range(100):
# x.append(random.randint(100, 150))
#或者这样写
x = [random.randint(50, 150) for _ in range(100)]
#组距与组数
d=10
num_bins=(max(x)-min(x))//d
print(max(x),min(x),max(x)-min(x),num_bins)
#设置图片大小,dpi越大越清晰
plt.figure(figsize=(10,8),dpi=80)
# 分布直方图,density表示是否是否将直方图归一化
plt.hist(x,num_bins,color="red",density=True)
# 取补步长,数字与字符串一一对应 ,rotation为旋转的度数
plt.xticks(range(min(x),max(x)+d,d),rotation=45)
#添加网格,alpha为透明度
plt.grid(alpha=0.4)
#添加描述信息
plt.xlabel("数字")
plt.ylabel("个数")
plt.title("变化")
#显示图片
plt.show()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。