数学建模--Radar图绘制

1.Radar图简介

   最近在数学建模中碰见需要绘制Radar图(雷达图)的情况来具体分析样本的各个特征之间的得分与优劣关系,这样的情况比较符合雷达图的使用场景,一般来说,雷达图适用于展示多个维度的数据,并在一个平面上直观地呈现出不同维度的变化趋势,比较适用的场合如下:

    ∙ \bullet 综合评价: 雷达图是理想的工具,能够直观展示多个评价指标的得分,为综合评估提供清晰的整体表现概览。

    ∙ \bullet SWOT分析: 通过SWOT分析,雷达图展示了组织或项目在各方面的优势、劣势、机会和威胁,为战略决策提供直观支持。

    ∙ \bullet 个体特征对比: 通过雷达图,我们可以比较不同个体在各个特征上的差异,无论是个人技能评估还是产品性能对比,一目了然。

2.Radar图绘图案例:单样本图绘制

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import warnings
warnings.filterwarnings("ignore")
matplotlib.rcParams['font.family'] = 'serif'
matplotlib.rcParams['font.serif'] = 'Times New Roman'
#需要评价的特征名称
labels = np.array(['Comprehensive', 'Education', 'Professional Title', 'Teaching', 'Training', 'Research'])
labels = np.array(['A1', 'A2', 'A3', 'A4', 'A5', 'A6'])
#需要评价的特征的数量
nAttr = len(labels)
#数据/得分情况
data = np.array([8, 5, 8, 9, 8, 6])
#计算角度360/n
angels = np.linspace(0, 2*np.pi, nAttr, endpoint=False)
#创建数据闭环效果
data = np.concatenate((data, [data[0]]))  
angels = np.concatenate((angels, [angels[0]]))#可视化绘图
fig = plt.figure(facecolor='white')
ax = plt.subplot(111, polar=True)ax.set_ylim(0, 10)
#绘制线条
ax.plot(angels, data, 'o-', color='lightgreen', linewidth=2, label='A Personal Characteristics')#添加数值标签(选写)
for i in range(len(angels)-1):ax.text(angels[i], data[i]+0.8, str(data[i]), color='b')#填充区域
ax.fill(angels, data, facecolor='red', alpha=0.25)
ax.set_xticks(angels[:-1])
ax.set_xticklabels(labels, ha='center')
ax.set_title('Academic Scholar Research Feature Radar Chart', va='bottom', fontweight='bold')
#设置一些图例要求
plt.grid(True)
#plt.legend(loc='upper right')
#plt.legend(loc='upper right', bbox_to_anchor=(1.2, 0.55), bbox_transform=plt.gcf().transFigure)
plt.savefig('雷达图1.jpg')
plt.show()

在这里插入图片描述

3.Radar图绘图案例:多样本图绘制

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import warningswarnings.filterwarnings("ignore")matplotlib.rcParams['font.family'] = 'serif'
matplotlib.rcParams['font.serif'] = 'Times New Roman'
matplotlib.rcParams['font.style'] = 'italic' radar_labels = np.array(['A1', 'A2', 'A3','A4', 'A5', 'A6'])
nAttr = 6data = np.array([[0.40, 0.32, 0.35, 0.30, 0.30, 0.88],[0.85, 0.35, 0.30, 0.40, 0.40, 0.30],[0.43, 0.89, 0.30, 0.28, 0.22, 0.30],[0.30, 0.25, 0.48, 0.85, 0.45, 0.40],[0.20, 0.38, 0.87, 0.45, 0.32, 0.28],[0.34, 0.31, 0.38, 0.40, 0.92, 0.28]])
data_labels = ('Engineer', 'Laboratory Technician', 'Artist', 'Salesperson', 'Social Worker', 'Clerk')angles = np.linspace(0, 2*np.pi, nAttr, endpoint=False)data = np.concatenate((data, [data[0]]))
angles = np.concatenate((angles, [angles[0]]))fig = plt.figure(facecolor='white')
ax = plt.subplot(111, polar=True)ax.plot(angles, data, 'o-', linewidth=1, alpha=0.2)
ax.fill(angles, data, alpha=0.3)ax.set_thetagrids(np.degrees(angles[0:6]), labels=radar_labels)
ax.set_title('Holland Personality Analysis', va='bottom', fontweight='bold', size=16)legend = plt.legend(data_labels, loc=(1.1, 0.55), labelspacing=0.1, edgecolor='k', fontsize=10)plt.grid(True)
plt.savefig('雷达图2.jpg')
plt.show()

在这里插入图片描述

4.Radar图绘图案例:Matplotlib标准绘图案例

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, RegularPolygon
from matplotlib.path import Path
from matplotlib.projections.polar import PolarAxes
from matplotlib.projections import register_projection
from matplotlib.spines import Spine
from matplotlib.transforms import Affine2Ddef radar_factory(num_vars, frame='circle'):"""Create a radar chart with `num_vars` axes.This function creates a RadarAxes projection and registers it.Parameters----------num_vars : intNumber of variables for radar chart.frame : {'circle', 'polygon'}Shape of frame surrounding axes."""# calculate evenly-spaced axis anglestheta = np.linspace(0, 2*np.pi, num_vars, endpoint=False)class RadarTransform(PolarAxes.PolarTransform):def transform_path_non_affine(self, path):# Paths with non-unit interpolation steps correspond to gridlines,# in which case we force interpolation (to defeat PolarTransform's# autoconversion to circular arcs).if path._interpolation_steps > 1:path = path.interpolated(num_vars)return Path(self.transform(path.vertices), path.codes)class RadarAxes(PolarAxes):name = 'radar'PolarTransform = RadarTransformdef __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)# rotate plot such that the first axis is at the topself.set_theta_zero_location('N')def fill(self, *args, closed=True, **kwargs):"""Override fill so that line is closed by default"""return super().fill(closed=closed, *args, **kwargs)def plot(self, *args, **kwargs):"""Override plot so that line is closed by default"""lines = super().plot(*args, **kwargs)for line in lines:self._close_line(line)def _close_line(self, line):x, y = line.get_data()# FIXME: markers at x[0], y[0] get doubled-upif x[0] != x[-1]:x = np.append(x, x[0])y = np.append(y, y[0])line.set_data(x, y)def set_varlabels(self, labels):self.set_thetagrids(np.degrees(theta), labels)def _gen_axes_patch(self):# The Axes patch must be centered at (0.5, 0.5) and of radius 0.5# in axes coordinates.if frame == 'circle':return Circle((0.5, 0.5), 0.5)elif frame == 'polygon':return RegularPolygon((0.5, 0.5), num_vars,radius=.5, edgecolor="k")else:raise ValueError("Unknown value for 'frame': %s" % frame)def _gen_axes_spines(self):if frame == 'circle':return super()._gen_axes_spines()elif frame == 'polygon':# spine_type must be 'left'/'right'/'top'/'bottom'/'circle'.spine = Spine(axes=self,spine_type='circle',path=Path.unit_regular_polygon(num_vars))# unit_regular_polygon gives a polygon of radius 1 centered at# (0, 0) but we want a polygon of radius 0.5 centered at (0.5,# 0.5) in axes coordinates.spine.set_transform(Affine2D().scale(.5).translate(.5, .5)+ self.transAxes)return {'polar': spine}else:raise ValueError("Unknown value for 'frame': %s" % frame)register_projection(RadarAxes)return thetadef example_data():# The following data is from the Denver Aerosol Sources and Health study.# See doi:10.1016/j.atmosenv.2008.12.017## The data are pollution source profile estimates for five modeled# pollution sources (e.g., cars, wood-burning, etc) that emit 7-9 chemical# species. The radar charts are experimented with here to see if we can# nicely visualize how the modeled source profiles change across four# scenarios:#  1) No gas-phase species present, just seven particulate counts on#     Sulfate#     Nitrate#     Elemental Carbon (EC)#     Organic Carbon fraction 1 (OC)#     Organic Carbon fraction 2 (OC2)#     Organic Carbon fraction 3 (OC3)#     Pyrolyzed Organic Carbon (OP)#  2)Inclusion of gas-phase specie carbon monoxide (CO)#  3)Inclusion of gas-phase specie ozone (O3).#  4)Inclusion of both gas-phase species is present...data = [['Sulfate', 'Nitrate', 'EC', 'OC1', 'OC2', 'OC3', 'OP', 'CO', 'O3'],('Basecase', [[0.88, 0.01, 0.03, 0.03, 0.00, 0.06, 0.01, 0.00, 0.00],[0.07, 0.95, 0.04, 0.05, 0.00, 0.02, 0.01, 0.00, 0.00],[0.01, 0.02, 0.85, 0.19, 0.05, 0.10, 0.00, 0.00, 0.00],[0.02, 0.01, 0.07, 0.01, 0.21, 0.12, 0.98, 0.00, 0.00],[0.01, 0.01, 0.02, 0.71, 0.74, 0.70, 0.00, 0.00, 0.00]]),('With CO', [[0.88, 0.02, 0.02, 0.02, 0.00, 0.05, 0.00, 0.05, 0.00],[0.08, 0.94, 0.04, 0.02, 0.00, 0.01, 0.12, 0.04, 0.00],[0.01, 0.01, 0.79, 0.10, 0.00, 0.05, 0.00, 0.31, 0.00],[0.00, 0.02, 0.03, 0.38, 0.31, 0.31, 0.00, 0.59, 0.00],[0.02, 0.02, 0.11, 0.47, 0.69, 0.58, 0.88, 0.00, 0.00]]),('With O3', [[0.89, 0.01, 0.07, 0.00, 0.00, 0.05, 0.00, 0.00, 0.03],[0.07, 0.95, 0.05, 0.04, 0.00, 0.02, 0.12, 0.00, 0.00],[0.01, 0.02, 0.86, 0.27, 0.16, 0.19, 0.00, 0.00, 0.00],[0.01, 0.03, 0.00, 0.32, 0.29, 0.27, 0.00, 0.00, 0.95],[0.02, 0.00, 0.03, 0.37, 0.56, 0.47, 0.87, 0.00, 0.00]]),('CO & O3', [[0.87, 0.01, 0.08, 0.00, 0.00, 0.04, 0.00, 0.00, 0.01],[0.09, 0.95, 0.02, 0.03, 0.00, 0.01, 0.13, 0.06, 0.00],[0.01, 0.02, 0.71, 0.24, 0.13, 0.16, 0.00, 0.50, 0.00],[0.01, 0.03, 0.00, 0.28, 0.24, 0.23, 0.00, 0.44, 0.88],[0.02, 0.00, 0.18, 0.45, 0.64, 0.55, 0.86, 0.00, 0.16]])]return dataif __name__ == '__main__':N = 9theta = radar_factory(N, frame='polygon')data = example_data()spoke_labels = data.pop(0)fig, axs = plt.subplots(figsize=(9, 9), nrows=2, ncols=2,subplot_kw=dict(projection='radar'))fig.subplots_adjust(wspace=0.25, hspace=0.20, top=0.85, bottom=0.05)colors = ['b', 'r', 'g', 'm', 'y']# Plot the four cases from the example data on separate axesfor ax, (title, case_data) in zip(axs.flat, data):ax.set_rgrids([0.2, 0.4, 0.6, 0.8])ax.set_title(title, weight='bold', size='medium', position=(0.5, 1.1),horizontalalignment='center', verticalalignment='center')for d, color in zip(case_data, colors):ax.plot(theta, d, color=color)ax.fill(theta, d, facecolor=color, alpha=0.25, label='_nolegend_')ax.set_varlabels(spoke_labels)# add legend relative to top-left plotlabels = ('Factor 1', 'Factor 2', 'Factor 3', 'Factor 4', 'Factor 5')legend = axs[0, 0].legend(labels, loc=(0.98, -0.2),labelspacing=0.1, fontsize=12,edgecolor='k')fig.text(0.5, 0.965, '5-Factor Solution Profiles Across Four Scenarios',horizontalalignment='center', color='black', weight='bold',size=16)plt.savefig('雷达图3.jpg')  plt.show()

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/421329.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Linux】基本指令收尾

文章目录 日期查找打包压缩系统信息Linux和Windows互传文件 日期 这篇是基本指令的收尾了,还有几个基本指令我们需要说一下 首先是Date,它是用来显示时间和日期 直接输入date的话显示是有点不好看的,所以我们可以根据自己的喜欢加上分隔符&…

【开源】基于JAVA的停车场收费系统

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 停车位模块2.2 车辆模块2.3 停车收费模块2.4 IC卡模块2.5 IC卡挂失模块 三、系统设计3.1 用例设计3.2 数据库设计3.2.1 停车场表3.2.2 车辆表3.2.3 停车收费表3.2.4 IC 卡表3.2.5 IC 卡挂失表 四、系统实现五、核心代码…

EtherNet/IP开发:C++开发CIP源代码

① 介绍一下CIP CIP是一种考虑到自动化行业而设计的通用协议。然而,由于其开放性,它可以并且已经应用于更多的领域。CIP网络库包含若干卷: 第1卷介绍了适用于所有网络自适应的CIP的常见方面。本卷包含通用对象库和设备配置文件库&#xff0…

Java基础篇----包机制与JavaDoc

作为一名对技术充满热情的学习者,我一直以来都深刻地体会到知识的广度和深度。在这个不断演变的数字时代,我远非专家,而是一位不断追求进步的旅行者。通过这篇博客,我想分享我在某个领域的学习经验,与大家共同探讨、共…

k8s 部署 Nginx 并代理到tomcat

一、已有信息 [rootmaster nginx]# kubectl get nodes -o wide [rootmaster nginx]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2…

Spring5系列学习文章分享---第一篇(概述+特点+IOC原理+IOC并操作之bean的XML管理操作)

目录 Spring&#xff08;概述特点IOC原理IOC并操作之bean的XML管理操作&#xff09;概述Spring是轻量级的开源的JavaEE框架Spring可以解决企业应用开发的复杂性Spring有两个核心部分ioc,aopSpring特点 loc(概念和原理)什么是 IOCIOC 底层原理IOC 过程图 IOC&#xff08;接口&am…

HarmonyOS鸿蒙应用开发 (一、环境搭建及第一个Hello World)

万事开头难。难在迈出第一步。心无旁骛&#xff0c;万事可破。没有人一开始就能想清楚&#xff0c;只有做起来&#xff0c;目标才会越来越清晰。--马克.扎克伯格 前言 2024年1月16日&#xff0c;华为目前开启已HarmonyOS NEXT开发者预览版Beta招募&#xff0c;报名周期为1月15…

【机组】微程序控制单元实验的解密与实战

​&#x1f308;个人主页&#xff1a;Sarapines Programmer&#x1f525; 系列专栏&#xff1a;《机组 | 模块单元实验》⏰诗赋清音&#xff1a;云生高巅梦远游&#xff0c; 星光点缀碧海愁。 山川深邃情难晤&#xff0c; 剑气凌云志自修。 ​ 目录 &#x1f33a;一、 实验目…

【数据结构与算法】1.数据结构绪论

&#x1f4da;博客主页&#xff1a;爱敲代码的小杨. ✨专栏&#xff1a;《Java SE语法》 ❤️感谢大家点赞&#x1f44d;&#x1f3fb;收藏⭐评论✍&#x1f3fb;&#xff0c;您的三连就是我持续更新的动力❤️ &#x1f64f;小杨水平有限&#xff0c;欢迎各位大佬指点&…

(2)(2.1) Andruav Android Cellular(二)

文章目录 前言 5 Andruav Web Client 6 Andruav Telemetry 7 Andruav高级功能 8 将Andruav与SITL配合使用 9 FAQ 10 术语表 前言 Andruav 是一个基于安卓的互联系统&#xff0c;它将安卓手机作为公司计算机&#xff0c;为你的无人机和遥控车增添先进功能。 5 Andruav W…

(1)C语言中的操作符(运算符):算术操作符(+、-、*、/、%)、赋值操作符(=)、单目操作符(++、--、+、-)介绍

目录 前言 一、算术操作符&#xff1a;、-、*、/、% 1. 和- 2. * 3. / 4. % 二、赋值操作符&#xff1a;和复合赋值 1. 连续赋值 2. 复合赋值符 三、单目操作符&#xff1a;、--、、- 1. (1) 前置 (2) 后置 2. -- (1) 前置-- (2) 后置-- 3. 和- 结语&am…

超级菜鸟怎么学习数据分析?

如果你有python入门基础&#xff0c;在考虑数据分析岗&#xff0c;这篇文章将带你了解&#xff1a;数据分析人才的薪资水平&#xff0c;数据人应该掌握的技术栈。 首先来看看&#xff0c;我在搜索数据分析招聘时&#xff0c;各大厂开出的薪资&#xff1a; 那各大厂在数据领域…