python之matplotlib制作雷达图

python之matplotlib制作雷达图

示例代码:

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(['综合','属性1','属性2','属性3','属性4','属性5'])
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]]))
labels=np.concatenate((labels,[labels[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)
plt.figtext(0.52,0.95,'XX属性图',ha='center')
plt.grid(True)
plt.show()

运行结果:

python之matplotlib制作雷达图_第1张图片

更改雷达图的夹角:

示例代码:

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(['综合','属性1','属性2','属性3','属性4','属性5'])
nAttr = 6
data = np.array([7,5,6,9,8,7])
# angles = np.linspace(0,2*np.pi,nAttr,endpoint=False)
angles = np.array([0.        , 1.3 , 2.0943951 , 3.14159265, 4 , 5.8])  # max=6.283185307179586

data = np.concatenate((data,[data[0]]))
angles = np.concatenate((angles,[angles[0]]))
labels=np.concatenate((labels,[labels[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)
plt.figtext(0.52,0.95,'XX属性图',ha='center')
plt.grid(True)
plt.show()

运行结果:

python之matplotlib制作雷达图_第2张图片

 

你可能感兴趣的:(机器学习,python,机器学习,可视化)