python可视化作图(11)---雷达值图

本文将介绍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']
"""

运行结果如下图:
在这里插入图片描述

以上就是本文所有内容,希望能帮到大家!!!

发布了44 篇原创文章 · 获赞 36 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/m0_45161766/article/details/104914462