matplotlib绘制雷达图报错记录

项目场景:

照着教科书敲代码绘制雷达图结果报错


问题描述:

报错类型:ValueError: The number of FixedLocator locations (7), usually from a call to set_ticks, does not match the number of ticklabels (6)

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(['综合','KDA','发育','推进','生存','输出'])
nAttr = 6
data = np.array([7,5,6,9,8,7])
angles = np.linspace(0,2*np.pi,nAttr,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,'bo-',color = 'g',linewidth = 2)
plt.fill(angles,data,facecolor = 'g',alpha = 0.25)
plt.thetagrids(angles*180/np.pi,labels = labels)
plt.figtext(0.52,0.95,"DOTA能力雷达值",ha = 'center')
plt.grid(True)
plt.savefig("dota_radar.JPG")
plt.show()
        }

原因分析:

python版本更新问题


解决方案:

将这两行代码注释掉:data = np.concatenate((data,[data[0]])) angles = np.concatenate((angles,[angles[0]]))

运行结果:

matplotlib绘制雷达图报错记录_第1张图片

你可能感兴趣的:(笔记,python,数据可视化)