有五个演员,各个演员的身高分别为177、174、170、178、173,请用jupyter notebook画出其分布与正态分布曲线
时间: 2023-07-10 11:03:42 浏览: 112
首先,我们需要导入需要用到的库:numpy、matplotlib 和 scipy。
代码如下:
```python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
```
接下来,我们定义演员的身高数据:
```python
height = [177, 174, 170, 178, 173]
```
然后,我们可以计算出演员身高的均值和标准差:
```python
mu, std = np.mean(height), np.std(height)
```
接下来,我们可以使用 matplotlib 库绘制演员身高的分布图:
```python
plt.hist(height, bins=5, density=True, alpha=0.6, color='b')
plt.title('Distribution of Actor Heights')
plt.xlabel('Height (cm)')
plt.ylabel('Probability Density')
plt.show()
```
这会得到以下的分布图:

最后,我们可以使用 scipy 库绘制演员身高的正态分布曲线:
```python
x = np.linspace(160, 190, 100)
plt.plot(x, norm.pdf(x, mu, std), 'r', lw=2)
plt.hist(height, bins=5, density=True, alpha=0.6, color='b')
plt.title('Distribution of Actor Heights')
plt.xlabel('Height (cm)')
plt.ylabel('Probability Density')
plt.show()
```
这会得到以下的图形:

这里,红色的曲线表示演员身高的正态分布曲线,蓝色的直方图表示演员身高的实际分布。
阅读全文
相关推荐










