首页 > 编程知识 正文

r语言画正态分布曲线,excel如何做正态分布曲线

时间:2023-05-04 19:52:26 阅读:154299 作者:3415

使用Python绘制正态分布曲线,并使用matplotlib绘制工具;

#-* -编码: utf-8-* -

“”'

python绘制标准正态分布曲线

“”'

#

导入编号为NP

导入匹配

import matplotlib.pyplot as plt

defGD(x,mu=0,sigma=1) :

基于“”表达式,根据自变量x计算因子的值

代理:

x :阵列

输入数据(参数) )。

mu :浮动

平均值

sigma :浮动

方差

“”'

left=1/(NP.sqrt )2* math.pi (NP.sqrt ) sigma ) )

right=NP.exp(-(x-mu ) *2/(sigma ) )

return left * right

if __name__=='__main__':

#参数

x=NP.arange (-4,5,0.1 ) ) ) ) ) )。

#因变量(平均值或方差) ) ) ) ) ) ) ) ) ) ) )。

y_1=GD(x,0,0.2 ) ) ) )。

y_2=GD(x,0,1.0 ) ) ) )。

y_3=GD(x,0,5.0 ) ) ) ) )。

y_4=GD(x,- 2,0.5 ) )。

#绘图

PLT.plot(x,y_1,color='green ' ) )。

PLT.plot(x,y_2,color='blue ' ) )。

PLT.plot(x,y_3,color='yellow ' ) )。

PLT.plot(x,y_4,color='red ' ) ) )。

#坐标系的设定

PLT.xlim (-5.0,5.0 ) ) ) )。

PLT.ylim (-0.2,1 ) )。

ax=plt.gca (

ax.spines [ ' right ' ].set _ color (' none ' )

ax.spines [ ' top ' ].set _ color (' none ' )

ax.xaxis.set _ ticks _ position (bottom ) )。

ax.spines [ ' bottom ' ].set _ position ((' data ',0 ) )

ax.yaxis.set _ ticks _ position (' left ' ) ) ) ) ) ) )。

ax.spines [ ' left ' ].set _ position ((data ',0 ) )

PLT.legend(labels=['$mu=0=0,sigma^2=0.2$ ',' $mu=0,' sigma^2=1.0$ ',$mu )

plt.show () )

以上是使用python制作正态分布曲线的详细内容。 关于python正态分布的资料请关注其他相关文章。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。