本文将介绍python可视化作雷达值图
以下是具体代码:
import numpy as np
import pylab as pl
labels=list("abcdefgh")
n=8
data=np.random.randint(5,10,(2,n))
angles=np.linspace(0,2*np.pi,n,endpoint=False)
data=np.hstack((data,data[:,0].reshape(-1,1)))
angles=np.hstack((angles,[angles[0]]))
fig=pl.figure()
ax=fig.add_subplot(111, polar=True)
ax.plot(angles,data[0],'ro-',linewidth=2)
ax.plot(angles,data[1],'bo-',linewidth=2)
ax.set_thetagrids(angles*180/np.pi,labels)
ax.set_title("雷达图",va='bottom',fontproperties="SimHei")
ax.grid(True)
pl.show()
""""
1、设置数据圈:data=np.hstack((data,data[:,0].reshape(-1,1)))
2、设置极坐标:fig=pl.figure()ax=fig.add_subplot(111, polar=True)
3、画线:ax.plot(angles,data[0],'ro-',linewidth=2)
4、设置中文显示:set_title中可以设置fontproperties
ax.set_title("雷达图",va='bottom',fontproperties="SimHei")
其他对象中如果没有字体属性如title,只能利用:
pl.rcParams['font.sans-serif']=['SimHei']或者['font.family']= ['SimHei']
"""
运行结果如下图: