python画雷伊代码
时间: 2024-05-13 10:12:29 浏览: 10
Python 画雷达图,也称为极坐标图,可以使用 Matplotlib 库中的 polar() 函数实现。下面是一个简单的例子:
```python
import matplotlib.pyplot as plt
import numpy as np
categories = ['A', 'B', 'C', 'D', 'E'] # 标签
data = [68, 83, 92, 78, 95] # 数据
angles = np.linspace(0, 2*np.pi, len(categories), endpoint=False) # 计算角度
data = np.concatenate((data, [data])) # 闭合数据
fig = plt.figure()
ax = fig.add_subplot(111, polar=True) # 极坐标系
ax.plot(angles, data, 'o-', linewidth=2) # 绘制雷达图
ax.fill(angles, data, alpha=0.25) # 填充雷达图
ax.set_thetagrids(angles * 180/np.pi, categories) # 设置极坐标系刻度
ax.set_title('Radar Chart') # 设置标题
ax.grid(True) # 显示网格线
plt.show()
```
其中,categories 是标签,data 是数据,angles 是计算得到的角度,fig 是图形对象,ax 是坐标系对象。通过 plot() 函数绘制雷达图,通过 fill() 函数填充雷达图,通过 set_thetagrids() 函数设置极坐标系刻度,通过 set_title() 函数设置标题,通过 grid() 函数显示网格线。