import matplotlib.pyplot as plt
import numpy as np
def radarMap(values, feature, labels, title):
# 中文和负号的正常显示
plt.rcParams[‘font.sans-serif’] = ‘Microsoft YaHei’
plt.rcParams[‘axes.unicode_minus’] = False
#使用ggplot的风格绘图
plt.style.use('ggplot')
N = len(feature)
#设置雷达图的角度,用于平分切开一个平面
angles = np.linspace(0,2*np.pi,N,endpoint=False)
#绘图
fig = plt.figure()
values = np.array(values)
for i in range(values.shape[0]):
value = values[i, :]
#设置为极坐标格式
ax = fig.add_subplot(111, polar=True)
#绘制折线图
ax.plot(angles,value,'o-',linewidth=2, label = labels[i])
ax.fill(angles,value,alpha=0.5)
#添加每个特质的标签
ax.set_thetagrids(angles*180/np.pi,feature)
#设置极轴范围
ax.set_ylim(0,5)
#添加标题
plt.title(title)
plt.legend(loc= 'best')
#增加网格纸
ax.grid(True)
plt.show()
values = [[3.2,2.1,3.5,2.8,3,4],
[2.4,3.1,4.1,1.9,3.5,2.3]]
feature = [‘个人能力’,‘QC知识’,“解决问题能力”,“服务质量意识”,“团队精神”,“IQ”]
labels=[‘before’, ‘after’]
title=‘综合素质评价表’
函数调用
radarMap(values, feature, labels, title)
CSDN搜索:Python雷达图 封装
R语言教程之----swirl教程