下面是一个正态分布的例子,介绍的很详细,通过对引用函数的改变还可以绘制诸如卡方分布,t分布等常见分布函数的绘制。
如需其他分布函数代码,可以查看我上传的代码文件,里面还包括了柯布-道格拉斯函数三维分布的函数图像。
Let 𝑋 be a random variable that follows the normal distribution, i.e.,
𝑋∼𝑁(𝑎,𝑏2),X∼N(a,b2),
where 𝑎 is the mean of X, and 𝑏 is the standard deviation of 𝑋.
- Plot the probability density function of 𝑋X when 𝑎=0a=0 and 𝑏=1,2,4b=1,2,4.
- Plot the cumulative distribution function of 𝑋X when 𝑎=0a=0 and 𝑏=1,2,4b=1,2,4.
-
#第一问 import numpy as np from scipy import stats import matplotlib.pyplot as plt mean=0 #定义函数:stats.norm(a,b)为正态分布的函数;stats.chi2为卡方分布的函数;stats.t为T分布的函数 normalDistribution=stats.norm(mean,1) #标准差=2的正态分布 normalDistribution1=stats.norm(mean,2) #标准差=4的正态分布 normalDistribution2=st