霍兰德人格分析雷达图的两个坑

#HollandRadarDraw.py
import numpy as np
import matplotlib.pyplot as plt 
import matplotlib

matplotlib.rcParams['font.family']="SimHei"
radar_labels = np.array(['研究型(I)','艺术型(A)','社会型(S)',\
                        '企业型(E)','常规型(C)','现实型(R)'])
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 =('艺术家','实验员','工程师','推销员','社会工作者','记事员')


angles = np.linspace(0, 2*np.pi, 6, endpoint=False)
data = np.concatenate((data, [data[0]]))
angles = np.concatenate((angles, [angles[0]]))
fig = plt.figure(facecolor = "white")
plt.subplot(111, polar = True)
plt.plot(angles, data,'o-',linewidth=1, alpha=0.2)
plt.fill(angles, data, alpha=0.25)
plt.thetagrids(angles*180/np.pi, radar_labels, frac=1.2)
plt.figtext(0.52, 0.95, '霍兰德人格分析', ha='center', size=20)
legend = plt.legend(data_labels, loc = (0.94, 0.80), labelspacing = 0.1)
plt.setp(legend.get_texts(), fontsize='large')
plt.grid(True)
plt.savefig('holland_radar.jpg')
plt.show()

运行出现错误
在这里插入图片描述

Exception has occurred: ValueError
The number of FixedLocator locations (7), usually from a call to set_ticks, does not match the number of ticklabels (6).
  File "D:\ex\HollandRadarDraw.py", line 25, in <module>
    plt.thetagrids(angles*180/np.pi, radar_labels, frac=1.2)

经查找,是matplotlib的版本问题,删掉
在这里插入图片描述
运行,出现错误
在这里插入图片描述

Exception has occurred: AttributeError
'Text' object has no property 'frac'
  File "D:\ex\HollandRadarDraw.py", line 25, in <module>
    plt.thetagrids(angles*180/np.pi, radar_labels, frac=1.2)

删掉‘frac=1.2’
运行成功
在这里插入图片描述
正确代码如下

#HollandRadarDraw.py
import numpy as np
import matplotlib.pyplot as plt 
import matplotlib

matplotlib.rcParams['font.family']="SimHei"
radar_labels = np.array(['研究型(I)','艺术型(A)','社会型(S)',\
                        '企业型(E)','常规型(C)','现实型(R)'])
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 =('艺术家','实验员','工程师','推销员','社会工作者','记事员')


angles = np.linspace(0, 2*np.pi, 6, endpoint=False)
fig = plt.figure(facecolor = "white")
plt.subplot(111, polar = True)
plt.plot(angles, data,'o-',linewidth=1, alpha=0.2)
plt.fill(angles, data, alpha=0.25)
plt.thetagrids(angles*180/np.pi, radar_labels)
plt.figtext(0.52, 0.95, '霍兰德人格分析', ha='center', size=20)
legend = plt.legend(data_labels, loc = (0.94, 0.80), labelspacing = 0.1)
plt.setp(legend.get_texts(), fontsize='large')
plt.grid(True)
plt.savefig('holland_radar.jpg')
plt.show()
  • 25
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值