plt.plot(x, norm_curve(0, 1, x), label='N(0,1)')是什么意思
时间: 2024-06-07 12:05:19 浏览: 20
ChitGPT: 这是一个 Python 中使用 Matplotlib 库绘制正态分布曲线的代码,其中 x 是自变量,norm_curve(0, 1, x) 是以 0 为均值,1 为标准差的正态分布在 x 处的概率密度函数。label='N(0,1)' 是为该曲线添加标签,用以说明该曲线是以 0 为均值,1 为标准差的正态分布曲线。
相关问题
创建一个函数def norm_curve (mu, sigma , x) 在同一个 figure 里面绘制 x ∼ N(0, 1), x ∼ N(2, 1), x ∼ N(0, 2) 的曲线图。
```python
import numpy as np
import matplotlib.pyplot as plt
def norm_curve(mu, sigma, x):
y = 1 / (sigma * np.sqrt(2*np.pi)) * np.exp(-(x-mu)**2 / (2*sigma**2))
return y
x = np.linspace(-5, 5, 1000)
y1 = norm_curve(0, 1, x)
y2 = norm_curve(2, 1, x)
y3 = norm_curve(0, 2, x)
plt.plot(x, y1, label='N(0,1)')
plt.plot(x, y2, label='N(2,1)')
plt.plot(x, y3, label='N(0,2)')
plt.legend()
plt.show()
```
运行结果:
![norm_curve](https://img-blog.csdnimg.cn/20211017173430632.png)
创建一个函数def norm_curve (mu, sigma , x) 能够返回任意均值或方差的正态分布曲线坐标 x,y利用刚才的函数,在同一个 figure 里面绘制 x ∼ N(0, 1), x ∼ N(2, 1), x ∼ N(0, 2) 的曲线图。
```python
import numpy as np
import matplotlib.pyplot as plt
def norm_curve(mu, sigma, x):
y = 1/(sigma * np.sqrt(2 * np.pi)) * np.exp(-(x - mu)**2 / (2 * sigma**2))
return y
x = np.linspace(-5, 5, 1000)
y1 = norm_curve(0, 1, x)
y2 = norm_curve(2, 1, x)
y3 = norm_curve(0, 2, x)
plt.plot(x, y1, label=r"$\mu=0,\sigma=1$")
plt.plot(x, y2, label=r"$\mu=2,\sigma=1$")
plt.plot(x, y3, label=r"$\mu=0,\sigma=2$")
plt.legend()
plt.show()
```
输出结果为:
![norm_curve](https://img-blog.csdnimg.cn/2022020719344039.png)
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)