python多级雷达图绘制
时间: 2023-10-14 22:30:34 浏览: 82
要绘制多级雷达图,可以使用 Python 的 Matplotlib 库。以下是一个简单的例子:
```
import numpy as np
import matplotlib.pyplot as plt
# 数据
categories = ['A', 'B', 'C', 'D', 'E']
data = np.array([[3, 4, 2, 1, 5], [4, 3, 5, 2, 1], [2, 5, 1, 4, 3]])
angles = np.linspace(0, 2*np.pi, len(categories), endpoint=False)
# 设置图形大小和标题
fig = plt.figure(figsize=(6, 6))
plt.suptitle('Multi-level Radar Chart')
# 绘制多级雷达图
ax = fig.add_subplot(111, polar=True)
ax.set_theta_offset(np.pi/2)
ax.set_theta_direction(-1)
for i in range(len(data)):
values = data[i]
values = np.concatenate((values, [values[0]]))
ax.plot(angles, values, label="Level {}".format(i+1))
ax.fill(angles, values, alpha=0.1)
# 设置轴标签和轴范围
ax.set_thetagrids(angles * 180/np.pi, categories)
ax.set_ylim(0, 5)
# 添加图例
plt.legend(loc='upper right', bbox_to_anchor=(1.2, 1.0))
# 显示图形
plt.show()
```
这个例子中,我们使用了 `numpy` 生成数据, `matplotlib.pyplot` 绘图,并使用了 `add_subplot()` 函数创建了一个极坐标子图。我们将不同级别的数据用不同颜色的线绘制,并用 `fill()` 函数填充颜色,最终得到了一个多级雷达图。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)
![](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)
![](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)