以下生成3个样本,每个样本5个特征,angles划分圆周,polar=True
表示画极线图,concatenate将数据和第一列拼接使得雷达图闭合。plot时传入极角angle和极径。
import matplotlib.pyplot as plt
import numpy as np
x = np.random.rand(3, 5)
angles = np.linspace(0, 2*np.pi, 5, endpoint=False) # 划分圆周
plot_data = np.concatenate((x, x[:, [0]]), axis=1)
angles = np.concatenate((angles, [angles[0]]))
colors = ['b', 'r', 'g', 'm', 'y']
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
for i in range(len(plot_data)):
ax.plot(angles, plot_data[i], 'o-', color=colors[i], linewidth=1.5, label=str(i))
# ax.fill(angles, plot_data[i], colors[i])
ax.set_thetagrids(angles * 180 / np.pi, ['A', 'B', 'C', 'D', 'E'])
plt.legend(loc='best')