给出goals = [70, 68, 87, 96, 58, 62, 78, 68, 84, 96] factor_a = [0.85, 0.75, 0.69, 0.7, 0.43, 0.52, 0.72, 0.62, 0.81, 0.89] factor_b = [1.78, 1.96, 1.82, 1.62, 1.78, 1.96, 1.53, 1.89, 1.72, 1.63],用python绘制其直方图、散点图和箱线图
时间: 2023-05-22 18:03:43 浏览: 73
以下是用python绘制goals列表直方图、散点图和箱线图的代码:
```python
import matplotlib.pyplot as plt
import numpy as np
goals = [70, 68, 87, 96, 58, 62, 78, 68, 84, 96]
factor_a = [0.85, 0.75, 0.69, 0.7, 0.43, 0.52, 0.72, 0.62, 0.81, 0.89]
factor_b = [1.78, 1.96, 1.82, 1.62, 1.78, 1.96, 1.53, 1.89, 1.72, 1.63]
# 绘制直方图
plt.hist(goals, bins=5)
plt.title('Goals Histogram')
plt.xlabel('Goals')
plt.ylabel('Frequency')
plt.show()
# 绘制散点图
plt.scatter(factor_a, factor_b)
plt.title('Scatter Plot')
plt.xlabel('Factor A')
plt.ylabel('Factor B')
plt.show()
# 绘制箱线图
data = [goals, factor_a, factor_b]
plt.boxplot(data)
plt.title('Box Plot')
plt.xticks([1, 2, 3], ['Goals', 'Factor A', 'Factor B'])
plt.show()
```
运行以上代码,可以得到三张图表,分别是直方图、散点图和箱线图,用以展示goals、factor_a和factor_b的数据分布情况。
阅读全文