linux 下matplotlib 运用二

import numpy as np
import matplotlib.pyplot as plt
#matplotlib.pyplot 是绘制各类可视化图形的命令子库
import matplotlib.mlab as mlab


#1)确定样本点
np.random.seed(0)
mu=100#均值
sigma=15#标准差
x=mu+sigma*np.random.randn(457)#标准正太分布与非标准正太分布相互转换 X~N(mu,sigma**2) Y=(X-mu)/sigma~N(0,1) 其中randn函数就是生成标准正太分布的样本数组点
print(x)
fig,axs=plt.subplots(1,2)#subplot_kw=dict(polar=True)polar极地图,类似于极坐标系图
ax1=axs[0]

n,bins,patches=ax1.hist(x=x,bins=50,normed=True,histtype='stepfilled',color=(0.6,0.5,0.3),alpha=0.75)#alpha透明度
'''
频率分布直方图
    x轴为样本数据的区间划分
    y轴为样本数据在 每个区间 的 频率分布 或者是 个数分布 情况
    :param x: 样本数据,是一个一维数组
    :param bin: 样本数据 最大值和最小值之间划分的区间的个数
    :param nomerd:True-->y轴是出现频率 (落在此区间的个数/总样本点个数) False -->点的个数
    :param histtype:{'bar', 'barstacked', 'step',  'stepfilled'}
'''
print("bins:",bins)#每一块bins 的edge值
x.sort()#从小到大排列
print("x:",x)#样本数据
y=mlab.normpdf(bins,mu,sigma)# 将bins数组的带入由mu sigma唯一确定额正太分布函数中,得出y值
ax1.plot(bins,y,'--')#scatter 散点图 plot线图
ax1.axis([0,200,0,1])#axis([x_start,x_end,y_start,y_end])
ax1.set_xlabel('Smarts')
ax1.set_ylabel('Probability density')#density  频率
ax1.set_title('Histogram IQ $\mu=100$, $\sigma=15$')

#fig.tight_layout()
plt.show()
plt.savefig('histogram_test1.png')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值