一、实例1:个人能力画像雷达图
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 1 20:52:54 2023
@author: zcq
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif']=['SimHei']
labels = np.array(['A1:综合','A2:学历','A3:职称','A4:教学','A5:培训','A6:科研'])
nAttr = 6
data = np.array([7,5,9,7,8,6])
angels = np.linspace(0,2*np.pi,nAttr,endpoint=False)
data = np.concatenate((data,[data[0]]))#级联函数data=[7, 5, 6, 9, 8, 6, 7]
angels = np.concatenate((angels,[angels[0]]))
fig = plt.figure(facecolor='white')
plt.subplot(111,polar=True)
plt.plot(angels,data,'bo-',color='g',linewidth=2)
plt.fill(angels,data,facecolor='g',alpha=0.25)
plt.thetagrids(angels*180/np.pi,labels)
plt.figtext(0.52,0.95,'个人特征画像',ha='center')
plt.grid(True)
plt.savefig('radar.jpg')
plt.show()
二、实例2:霍兰德人格分析雷达图
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 1 20:52:54 2023
@author: zcq
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif']=['SimHei']
radar_labels = np.array(['A1:研究型(I)','A2:艺术型(A)','A3:社会型(S)',\
'A4:企业型(E)','A5:常规型(C)','A6:现实型(R)'])
nAttr = 6
data = np.array([[0.40,0.32,0.35,0.30,0.30,0.88],
[0.85,0.35,0.30,0.40,0.40,0.30],
[0.43,0.89,0.30,0.28,0.22,0.30],
[0.30,0.25,0.48,0.85,0.45,0.40],
[0.20,0.38,0.87,0.45,0.32,0.28],
[0.34,0.31,0.38,0.40,0.92,0.28]])
data_labels = ('工程师','实验员','艺术家','推销员','社会工作者','记事员')
angels = np.linspace(0,2*np.pi,nAttr,endpoint=False)
data = np.concatenate((data,[data[0]]))
angels = np.concatenate((angels,[angels[0]]))
fig = plt.figure(facecolor='white')
plt.subplot(111,polar=True)
plt.plot(angels,data,'o-',linewidth=1,alpha=0.2)
plt.fill(angels,data,alpha=0.25)
plt.thetagrids(angels*180/np.pi,radar_labels)
plt.figtext(0.52,0.95,'霍兰德人格分析',ha='center',size=20)
legend = plt.legend(data_labels,loc=(0.94,0.8),labelspacing=0.1)
plt.setp(legend.get_texts(),fontsize='small')
plt.grid(True)
plt.savefig('Holland_radar.jpg')
plt.show()
【参考文献】嵩天,礼欣,黄天羽著,python语言程序设计基础(第2版)[M],北京:高等教育出版社,2020.2
【参考链接】https://blog.csdn.net/weixin_44940191/article/details/126910761