python数据雷达图

雷达图主要重点就是需要闭合数据,相当于形成一个闭环,要回到起始点

一组数据的雷达图

import numpy as np
import matplotlib.pyplot as plt
import matplotlib

matplotlib.rcParams['font.family'] = 'SimHei'  # 将字体设置为黑体'SimHei'
matplotlib.rcParams['font.sans-serif'] = ['SimHei']

labels = np.array(["成房网", "房天下", "链家", "楼盘网", "房产超市", "贝壳找房", "安居客"])
dataLenth = 7  # 数据长度
data = np.array([19, 103, 206, 317, 99, 209, 257])
angles = np.linspace(0, 2 * np.pi, dataLenth, endpoint=False)  # 根据数据长度平均分割圆周长

# 闭合
data = np.concatenate((data, [data[0]]))
angles = np.concatenate((angles, [angles[0]]))
labels = np.concatenate((labels, [labels[0]]))  # 对labels进行封闭

fig = plt.figure(facecolor="white")  # facecolor 设置框体的颜色
plt.subplot(111, polar=True)  # 将图分成1行1列,画出位置1的图;设置图形为极坐标图
plt.plot(angles, data, 'bo-', color='g', linewidth=2)
plt.fill(angles, data, facecolor='g', alpha=0.25)  # 填充两条线之间的色彩,alpha为透明度
plt.thetagrids(angles * 180 / np.pi, labels)  # 做标签
plt.figtext(0.52,0.95,'天府新区新房楼盘数量雷达图',ha='center')   #添加雷达图标题
plt.grid(True)
plt.show()

多组数据的雷达图

import numpy as np
import matplotlib.pyplot as plt
# 用于正常显示中文
plt.rcParams['font.sans-serif'] = 'SimHei'
#用于正常显示符号
plt.rcParams['axes.unicode_minus'] = False
 
# 使用ggplot的绘图风格,这个类似于美化了,可以通过plt.style.available查看可选值,你会发现其它的风格真的丑。。。
plt.style.use('ggplot')
 
# 构造数据
values1 = [2.6,2.1,3.4,3,4.1]
values2 = [1.7,4.1,3.3,2.6,3.8]
feature = ['个人能力','QC知识','解决问题能力','服务质量意识','团队精神']
 
# 设置每个数据点的显示位置,在雷达图上用角度表示
angles=np.linspace(0, 2*np.pi,len(feature), endpoint=False)
angles=np.concatenate((angles,[angles[0]]))
# 绘图
fig=plt.figure()
for values in [values1, values2]:
# 拼接数据首尾,使图形中线条封闭
    values=np.concatenate((values,[values[0]]))
    # 设置为极坐标格式
    ax = fig.add_subplot(111, polar=True)
    # 绘制折线图
    ax.plot(angles, values, 'o-', linewidth=2)
    # 填充颜色
    ax.fill(angles, values, alpha=0.25)
     
    # 设置图标上的角度划分刻度,为每个数据点处添加标签
    ax.set_thetagrids(angles * 180/np.pi, feature)
     
    # 设置雷达图的范围
    ax.set_ylim(0,5)
# 添加标题
plt.title('活动前后员工状态表现')
# 添加网格线
ax.grid(True)
 
plt.show()
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值