python可视化之雷达图

import numpy as np
import matplotlib.pyplot as plt
# 标签 label
labels = np.array(['3','5','6','3','1','3','3','2'])
# 数据个数
dataLenth = 8
# 数据
data = np.array([3,5,6,3,1,3,3,2])
# 设置雷达图的角度,用于平分切开一个圆面,dataLenth是一个变量,指属性个数,可以自己设置,是将圆分成多少块
angles = np.linspace(0,2*np.pi,dataLenth,endpoint=False)
# 也是为了雷达图封闭起来
data = np.concatenate((data,[data[0]]))
# 为了使雷达图一圈封闭起来
angles = np.concatenate((angles,[angles[0]]))

# 用来设置画布大小
fig = plt.figure()
# 这里一定要设置成极坐标格式
ax = fig.add_subplot(111,polar=True)
# 绘制折线图
ax.plot(angles,data,'ro-',linewidth=2)
# 添加每个特征的标签
ax.set_thetagrids(angles*180/np.pi,labels,fontproperties="SimHei")
# 添加标题形式
ax.set_title("温度变化表雷达图",va='bottom',fontproperties="SimHei")
# 添加网格线
ax.grid(True)
plt.savefig('4.png')
plt.show()

你可能感兴趣的:(python可视化之雷达图)