一、概念

雷达图是一种由一系列等角辐条(称为半径)组成的图表,每个辐条代表一个变量。轮辐的数据长度与数据点变量的大小相对于所有数据点上变量的最大大小成正比。绘制一条线,连接每个辐条的数据值。这使该图块具有星形外观,所以又叫星图。

二、用途

主要用途观察最相似,是否有离群点。多用于控制质量改进,便于观察性能指标。也常用于表示技能的长处和短处。

三、画图

"""
======================================
Radar chart (aka spider or star chart)
======================================
This example creates a radar chart, also known as a spider or star chart [1]_.
Although this example allows a frame of either 'circle' or 'polygon', polygon
frames don't have proper gridlines (the lines are circles instead of polygons).
It's possible to get a polygon grid by setting GRIDLINE_INTERPOLATION_STEPS in
matplotlib.axis to the desired number of vertices, but the orientation of the
polygon is not aligned with the radial axes.
.. [1] http://en.wikipedia.org/wiki/Radar_chart
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.path import Path
from matplotlib.spines import Spine
from matplotlib.projections.polar import PolarAxes
from matplotlib.projections import register_projectiondef 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)#角度(弧度制)def draw_poly_patch(self):# rotate theta such that the first axis is at the topverts = unit_poly_verts(theta + np.pi / 2)return plt.Polygon(verts, closed=True, edgecolor='k')def draw_circle_patch(self):# unit circle centered on (0.5, 0.5)return plt.Circle((0.5, 0.5), 0.5) #画圆patch_dict = {'polygon': draw_poly_patch, 'circle': draw_circle_patch}if frame not in patch_dict:raise ValueError('unknown value for `frame`: %s' % frame)class RadarAxes(PolarAxes):name = 'radar'# use 1 line segment to connect specified pointsRESOLUTION = 1# define draw_frame methoddraw_patch = patch_dict[frame]def __init__(self, *args, **kwargs):super(RadarAxes, self).__init__(*args, **kwargs)# rotate plot such that the first axis is at the topself.set_theta_zero_location('N')def fill(self, *args, **kwargs):"""Override fill so that line is closed by default"""closed = kwargs.pop('closed', True)return super(RadarAxes, self).fill(closed=closed, *args, **kwargs)def plot(self, *args, **kwargs):"""Override plot so that line is closed by default"""lines = super(RadarAxes, self).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.concatenate((x, [x[0]]))y = np.concatenate((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):return self.draw_patch()def _gen_axes_spines(self):if frame == 'circle':return PolarAxes._gen_axes_spines(self)# The following is a hack to get the spines (i.e. the axes frame)# to draw correctly for a polygon frame.# spine_type must be 'left', 'right', 'top', 'bottom', or `circle`.spine_type = 'circle'verts = unit_poly_verts(theta + np.pi / 2)# close off polygon by repeating first vertexverts.append(verts[0])path = Path(verts)spine = Spine(self, spine_type, path)spine.set_transform(self.transAxes)return {'polar': spine}register_projection(RadarAxes)return thetadef unit_poly_verts(theta):"""Return vertices of polygon for subplot axes.This polygon is circumscribed by a unit circle centered at (0.5, 0.5)"""x0, y0, r = [0.5] * 3verts = [(r*np.cos(t) + x0, r*np.sin(t) + y0) for t in theta]return vertsdef 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)#     Pyrolized 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, axes = 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(axes.flatten(), 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)##填充ax.set_varlabels(spoke_labels)# add legend relative to top-left plotax = axes[0, 0]labels = ('Factor 1', 'Factor 2', 'Factor 3', 'Factor 4', 'Factor 5')legend = ax.legend(labels, loc=(0.9, .95),labelspacing=0.1, fontsize='small')fig.text(0.5, 0.965, '5-Factor Solution Profiles Across Four Scenarios',horizontalalignment='center', color='black', weight='bold',size='large')plt.show()

python画蛛网图(雷达图)相关推荐

  1. python画出的雷达图效果-PYTHON绘制雷达图代码实例

    这篇文章主要介绍了PYTHON绘制雷达图代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.雷达图 import matplotlib.py ...

  2. python画雷达图-python使用matplotlib绘制雷达图

    本文实例为大家分享了python使用matplotlib绘制雷达图的具体代码,供大家参考,具体内容如下 示例代码: # encoding: utf-8 import pandas as pd impo ...

  3. 可视化实验十一:利用Python绘制气泡图、雷达图

    实验目的: 掌握Python中气泡图.雷达图绘图函数的使用及展示图形的意义 利用上述绘图函数实现数据可视化 实验内容: 练习python中气泡图.雷达图绘图函数的用法,掌握相关参数的概念 根据步骤一绘 ...

  4. python之matplotlib制作雷达图

    python之matplotlib制作雷达图 示例代码: import numpy as np import matplotlib.pyplot as plt import matplotlibmat ...

  5. python使用matplotlib可视化雷达图(polar函数可视化雷达图、极坐标图、通过径向方向来显示数据之间的关系)

    python使用matplotlib可视化雷达图(polar函数可视化雷达图.极坐标图.通过径向方向来显示数据之间的关系) 目录

  6. python话雷达图-python使用matplotlib绘制雷达图

    本文实例为大家分享了python使用matplotlib绘制雷达图的具体代码,供大家参考,具体内容如下 示例代码: # encoding: utf-8 import pandas as pd impo ...

  7. python画轨迹曲线-python 画3维轨迹图并进行比较的实例

    一. 数据的格式 首先我们需要x,y,z三个数据进行画图.从本实验用到的数据集KITTI 00.txt中举例: 1.000000e+00 9.043680e-12 2.326809e-11 5.551 ...

  8. python绘制雷达图代码实例-python处理excel绘制雷达图

    本文实例为大家分享了python处理excel绘制雷达图的具体代码,供大家参考,具体内容如下 python处理excel制成雷达图,利用工具plotly在线生成,事先要安装好xlrd组件 代码: im ...

  9. python绘制三维散点图-python 画三维图像 曲面图和散点图的示例

    用python画图很多是根据z=f(x,y)来画图的,本博文将三个对应的坐标点输入画图: 散点图: import matplotlib.pyplot as plt from mpl_toolkits. ...

  10. Python数据展示之雷达图

    Python数据展示之雷达图 简单实例 需求:雷达图方式验证霍兰德人格分析 输入:各职业人群结合兴趣的调研数据 输出:雷达图 使用库:matplotlib+numpy 代码 import numpy ...

最新文章

  1. left join on 和where条件的放置
  2. 嵌入式linux 考试大纲,《嵌入式Linux》课程考试大纲-武汉工程大学学生进
  3. 一文精简介绍CNN基本结构
  4. 翻译-Salt与Ansible全方位比较
  5. Adding a new op when using tensorflow in windows
  6. 雨林木风“115网络U盘”免费永久空间速度还挺快的
  7. C++新旧类型转换小记
  8. HEVC 编解码资源
  9. Python3爬取影片入库
  10. 物联网os_用于物联网的FireFox OS,NextCloud公告以及更多新闻
  11. mysql多表查询练习_MySQL多表查询综合练习答案
  12. 一起来做一个 c++ 单项选择题标准化考试系统
  13. 网站架构优化之css+div设计对SEO的影响
  14. 【申博攻略】四.博士申请的个人自述怎么写
  15. python绘制分形图基础_Python 绘制分形图(曼德勃罗集、分形树叶、科赫曲线、分形龙、谢尔宾斯基三角等)附代码...
  16. 如何制作二维码分享WiFi密码
  17. 国际域名缩写____各个国家
  18. 能测试成绩的学习软件,普通话学习测试这个软件上,我平均成绩能达到二甲,请问如果在真正的普通话考试上,我大概能得到什么等级...
  19. 操作无法完成错误0x0000709再次检查打印机名称解决方法!
  20. 让你的APP轻松加上扫描二维码功能

热门文章

  1. 高扽数学---第一章一元函数求极限三大方法---洛必达法则,泰勒公式
  2. 广告系统中通道类推送服务实践
  3. spring中No bean named xxx available错误
  4. 分账系统多少钱一套?
  5. 【图像分割】分割网络概览
  6. 试用用友致远最新版协同产品A8之二 1
  7. 血糖仪测血糖准确吗?选对血糖仪,才能精准测糖
  8. Apollo 障碍物感知5大板块(推荐了解)
  9. 黑马程序员学习笔记 关于继承
  10. spring aop 实现系统操作日志记录存储到数据库