import numpy as np import matplotlib.pyplot as plt plt.rcParams['font.family'] = 'SimHei' plt.rcParams['axes.unicode_minus'] = False data_5 = np.array([2450,2450,1598,1479.5,1550,1486.5]) data_6 = np.array([1379.5,1378,1350,1338.4,1300,1139.5,1126.5]) data_7 = np.array([1099,1099,1099,1079,1079,1024.5]) data_8 = np.array([1035,1035,1079.5,1126.5,1400,1396,1364.5]) data_9 = np.array([1500,1399,1490,1333.33,1350,1300]) data_10 = np.array([1269.9,1269.4,115,1149.5,1149]) data_11 = np.array([1149,1280,1260,1255,1235,1100]) data_12 = np.array([1040,1040,999,999,938.5]) data_13 = np.array([900,845,894.49,765.49,740,649.5,649.5]) data_14 = np.array([649.47,649.46,649.46,649,639,644]) data_15 = np.array([648.79,649.5,879,799,799,859.89]) data_16 = np.array([857.89,849.99,848.96,848.7,845.9]) plt.boxplot([data_5, data_6, data_7, data_8, data_9, data_10, data_11, data_12, data_13, data_14, data_15, data_16], labels=('5日', '6日','7日','8日','9日','10日' ,'11日','12日','13日','14日','15日','16日') ) plt.show()修改为雷达图
时间: 2023-07-31 13:12:24 浏览: 145
对于这个数据集,我们可以使用雷达图来进行可视化。下面是修改后的代码:
```python
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
# 数据
data_5 = np.array([2450,2450,1598,1479.5,1550,1486.5])
data_6 = np.array([1379.5,1378,1350,1338.4,1300,1139.5,1126.5])
data_7 = np.array([1099,1099,1099,1079,1079,1024.5])
data_8 = np.array([1035,1035,1079.5,1126.5,1400,1396,1364.5])
data_9 = np.array([1500,1399,1490,1333.33,1350,1300])
data_10 = np.array([1269.9,1269.4,115,1149.5,1149])
data_11 = np.array([1149,1280,1260,1255,1235,1100])
data_12 = np.array([1040,1040,999,999,938.5])
data_13 = np.array([900,845,894.49,765.49,740,649.5,649.5])
data_14 = np.array([649.47,649.46,649.46,649,639,644])
data_15 = np.array([648.79,649.5,879,799,799,859.89])
data_16 = np.array([857.89,849.99,848.96,848.7,845.9])
# 计算每个数据集的均值
means = [np.mean(data) for data in [data_5, data_6, data_7, data_8, data_9, data_10, data_11, data_12, data_13, data_14, data_15, data_16]]
# 构造标签和角度
labels = ('5日', '6日','7日','8日','9日','10日' ,'11日','12日','13日','14日','15日','16日')
angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
# 将数据首尾相连
means = np.concatenate((means, [means[0]]))
angles = np.concatenate((angles, [angles[0]]))
# 绘制雷达图
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.plot(angles, means, 'o-', linewidth=2)
ax.fill(angles, means, alpha=0.25)
ax.set_thetagrids(angles * 180/np.pi, labels)
ax.set_title('每日数据', fontsize=14)
ax.grid(True)
plt.show()
```
运行后可以得到如下的雷达图:
![radar](https://img-blog.csdnimg.cn/20210728212958112.png)
阅读全文