python--绘制雷达图

#新增加的两行
import matplotlib
matplotlib.rc("font",family='SimHei')

import numpy as np
import matplotlib.pyplot as plt

# 定义能力维度
labels=np.array(['团队意识', '质量意识', '自动化意识', '创新意识', '工作热情', '改进意识'])

# 原始数据和变化后的对比数据
values_before = np.array([7, 6, 5, 6, 7, 6])
values_after = np.array([9, 8, 9, 9, 8, 8])

# 计算角度
angles=np.linspace(0, 2*np.pi, len(labels), endpoint=False).tolist()

# 使雷达图封闭
values_before=np.concatenate((values_before,[values_before[0]]))
values_after=np.concatenate((values_after,[values_after[0]]))
angles+=angles[:1]

# 画图
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))

# 雷达填充
ax.fill(angles, values_before, color='salmon', alpha=0.5)
ax.fill(angles, values_after, color='lightblue', alpha=0.5)

# 添加连线
ax.plot(angles, values_before, color='red', linewidth=1.5, linestyle='dashed')
ax.plot(angles, values_after, color='blue', linewidth=1.5, linestyle='dashed')

# 标注数值
for i in range(len(labels)):
    ax.annotate(values_before[i], (angles[i], values_before[i]), textcoords="offset points", xytext=(0,10), ha='center', fontsize=12, color='darkred')
    ax.annotate(values_after[i], (angles[i], values_after[i]), textcoords="offset points", xytext=(0,10), ha='center', fontsize=12, color='darkblue')

# 设置标签
ax.set_yticklabels([])
ax.set_xticks(angles[:-1])
ax.set_xticklabels(labels, fontsize=12)

# 添加标题
plt.title('能力雷达图', size=20, color='black', y=1.1)

# 添加图例
plt.legend(['QC前', 'QC后'], loc='upper right')

plt.show()

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值