MATLAB绘制雷达图并导出矢量图到Visio编辑(论文用图)


前言: matlab绘制雷达图

  雷达图(Radar Chart)又被叫做蜘蛛网图(Spider Chart),适用于显示三个或更多的维度的变量。雷达图是以在同一点开始的轴上显示的三个或更多个变量的二维图表的形式来显示多元数据的方法,其中轴的相对位置和角度通常是无意义的。

  雷达图的每个变量都有一个从中心向外发射的轴线,所有的轴之间的夹角相等,同时每个轴有相同的刻度,将轴到轴的刻度用网格线链接作为辅助元素,连接每个变量在其各自的轴线的数据点成一条多边形[1]。

  下面第一部分是MATLAB绘制雷达图,第二部分是MATLAB到处矢量图设置,以便于到Visio编辑

tips: 操作环境: Win10, MATLAB 2020a


一、MATLAB绘制雷达图

1.1 操作简介

   GitHub一位前辈使用matlab封装了绘制雷达图的代码,打开matlab新建一个.m文件存入代码,再新建一个.m文件调用github下载的代码中的函数即可,具体操作如下:

Step1 : 复制下面代码到自己新建的脚本文件中(.m文件)

tips: 最好新建一个文件夹,把新建的两个.m文件都放到这一个文件夹中,其中源代码文件命名为 spider_plot.m, 即与函数名一致。

function spider_plot(P, P_labels, axes_interval, axes_precision, varargin)
% Create a spider web or radar plot with an axes specified for each column
%
% spider_plot(P, P_labels, axes_interval, axes_precision) creates a spider
% web plot using the points specified in the array P. The column of P
% contains the data points and the rows of P contain the multiple sets of
% data points. Each point must be accompanied by a label specified in the
% cell P_labels. The number of intervals that separate the axes is
% specified by axes_interval. The number of decimal precision points is
% specified by axes_precision.
%
% P - [vector | matrix]
% P_labels - [cell of string]
% axes_interval - [integer]
% axes_precision - [integer]
%
% spider_plot(P, P_labels, axes_interval, axes_precision, line_spec) works
% the same as the function above. Additional line properties can be added
% in the same format as the default "plot" function in MATLAB.
%
% line_spec - [character vector]
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Point Properties %%%
% Number of points
[row_of_points, num_of_points] = size(P);
%%% Error Check %%%
% Check if axes properties are an integer
if floor(axes_interval) ~= axes_interval || floor(axes_precision) ~= axes_precisionerror('Error: Please enter in an integer for the axes properties.');
end
% Check if axes properties are positive
if axes_interval < 1 || axes_precision < 1error('Error: Please enter value greater than one for the axes properties.');
end
% Check if the labels are the same number as the number of points
if length(P_labels) ~= num_of_pointserror('Error: Please make sure the number of labels is the same as the number of points.');
end
% Pre-allocation
max_values = zeros(1, num_of_points);
min_values = zeros(1, num_of_points);
axis_increment = zeros(1, num_of_points);
% Normalized axis increment
normalized_axis_increment = 1/axes_interval;
% Iterate through number of points
for ii = 1:num_of_points% Group of pointsgroup_points = P(:, ii);% Max and min value of each groupmax_values(ii) = max(group_points);min_values(ii) = min(group_points);range = max_values(ii) - min_values(ii);% Axis incrementaxis_increment(ii) = range/axes_interval;% Normalize points to range from [0, 1]P(:, ii) = (P(:, ii)-min(group_points))/range;% Shift points by one axis incrementP(:, ii) = P(:, ii) + normalized_axis_increment;
end
%%% Polar Axes %%%
% Polar increments
polar_increments = 2*pi/num_of_points;
% Normalized  max limit of axes
axes_limit = 1;
% Shift axes limit by one axis increment
axes_limit = axes_limit + normalized_axis_increment;
% Polar points
radius = [0; axes_limit];
theta = 0:polar_increments:2*pi;
% Convert polar to cartesian coordinates
[x_axes, y_axes] = pol2cart(theta, radius);
% Plot polar axes
grey = [1, 1, 1] * 0.5;
h = line(x_axes, y_axes,...'LineWidth', 1,...'Color', grey);
% Iterate through all the line handles
for ii = 1:length(h)% Remove polar axes from legendh(ii).Annotation.LegendInformation.IconDisplayStyle = 'off';
end
%%% Polar Isocurves %%%
% Shifted axes interval
shifted_axes_interval = axes_interval+1;
% Incremental radius
radius = (0:axes_limit/shifted_axes_interval:axes_limit)';
% Convert polar to cartesian coordinates
[x_isocurves, y_isocurves] = pol2cart(theta, radius);
% Plot polar isocurves
hold on;
h = plot(x_isocurves', y_isocurves',...'LineWidth', 1,...'Color', grey);
% Iterate through all the plot handles
for ii = 1:length(h)% Remove polar isocurves from legendh(ii).Annotation.LegendInformation.IconDisplayStyle = 'off';
end
%%% Figure Properties %%%
colors = [0, 0.4470, 0.7410;...0.8500, 0.3250, 0.0980;...0.9290, 0.6940, 0.1250;...0.4940, 0.1840, 0.5560;...0.4660, 0.6740, 0.1880;...0.3010, 0.7450, 0.9330;...0.6350, 0.0780, 0.1840];
% Repeat colors is necessary
repeat_colors = fix(row_of_points/size(colors, 1))+1;
colors = repmat(colors, repeat_colors, 1);
%%% Data Points %%%
% Iterate through all the rows
for ii = 1:row_of_points% Convert polar to cartesian coordinates[x_points, y_points] = pol2cart(theta(1:end-1), P(ii, :));% Make points circularx_circular = [x_points, x_points(1)];y_circular = [y_points, y_points(1)];% Plot data pointsplot(x_circular, y_circular,...'Color', colors(ii, :),...'MarkerFaceColor', colors(ii, :),...varargin{:});
end
%%% Axis Properties %%%
% Figure background
fig = gcf;
fig.Color = 'white';
% Iterate through all the number of points
for hh = 1:num_of_points% Shifted min valueshifted_min_value = min_values(hh)-axis_increment(hh);% Axis label for each rowrow_axis_labels = (shifted_min_value:axis_increment(hh):max_values(hh))';% Iterate through all the isocurve radiusfor ii = 2:length(radius)% Display axis text for each isocurvetext(x_isocurves(ii, hh), y_isocurves(ii, hh), sprintf(sprintf('%%.%if', axes_precision), row_axis_labels(ii)),...'Units', 'Data',...'Color', 'k',...'FontSize', 10,...'HorizontalAlignment', 'center',...'VerticalAlignment', 'middle');end
end
% Label points
x_label = x_isocurves(end, :);
y_label = y_isocurves(end, :);
% Shift axis label
shift_pos = 0.07;
% Iterate through each label
for ii = 1:num_of_points% Angle of point in radianstheta_point = theta(ii);% Find out which quadrant the point is inif theta_point == 0quadrant = 0;elseif theta_point == pi/2quadrant = 1.5;elseif theta_point == piquadrant = 2.5;elseif theta_point == 3*pi/2quadrant = 3.5;elseif theta_point == 2*piquadrant = 0;elseif theta_point > 0 && theta_point < pi/2quadrant = 1;elseif theta_point > pi/2 && theta_point < piquadrant = 2;elseif theta_point > pi && theta_point < 3*pi/2quadrant = 3;elseif theta_point > 3*pi/2 && theta_point < 2*piquadrant = 4;end% Adjust text alignment information depending on quadrantswitch quadrantcase 0horz_align = 'left';vert_align = 'middle';x_pos = shift_pos;y_pos = 0;case 1horz_align = 'left';vert_align = 'bottom';x_pos = shift_pos;y_pos = shift_pos;case 1.5horz_align = 'center';vert_align = 'bottom';x_pos = 0;y_pos = shift_pos;case 2horz_align = 'right';vert_align = 'bottom';x_pos = -shift_pos;y_pos = shift_pos;case 2.5horz_align = 'right';vert_align = 'middle';x_pos = -shift_pos;y_pos = 0;case 3horz_align = 'right';vert_align = 'top';x_pos = -shift_pos;y_pos = -shift_pos;case 3.5horz_align = 'center';vert_align = 'top';x_pos = 0;y_pos = -shift_pos;case 4horz_align = 'left';vert_align = 'top';x_pos = shift_pos;y_pos = -shift_pos;end% Display text labeltext(x_label(ii)+x_pos, y_label(ii)+y_pos, P_labels{ii},...'Units', 'Data',...'HorizontalAlignment', horz_align,...'VerticalAlignment', vert_align,...'EdgeColor', 'k',...'BackgroundColor', 'w');
end
% Axis limits
axis square;
axis([-axes_limit, axes_limit, -axes_limit, axes_limit]);
axis off;
end

注: 上面的源代码也可以在github下载,链接为
NewGuy012/spider_plot [2],源代码里面有很多,单纯为了应用的话上述代码足矣。


Step2 : 在测试文件中输入测试代码测试(后有测试代码说明)

在test.m 中输入如下代码:

%% Example Script %%%
% Clear workspace
close all;
clearvars;
clc;% Point properties
num_of_points = 6;  % 6项指标
row_of_points = 4;  % 4中方案对比     这两个定义即为这个雷达图定义了范围% indicator 这个变量存放6项指标的名字,便于作为label在雷达图上显示
indicator = ["成本经济性" "操作简易性" "安全性" "运输便利度" "技术成熟度" "体积比容量" ];
% Random data 这里例子是给的随机数据,我自己根据需要给定了数据,其中各项的对比是根据满分1分给各个方案对特定指标打分的
%P = rand(row_of_points, num_of_points);
% 下面这个P即为自己定义的变量,是一个4*6的矩阵,
% 第i(1<= i <=6)列即表示这四种方案对第i个指标的评分高低对应具体数值
P =  [0.85 0.8 0.3 0.75 0.87 0.45;0.75 0.35 0.45 0.638 0.7 0.9;0.45 0.65 0.96 0.95 0.3 0.85; 0.3 0.6 0.99 0.98 0.83 0.8];
% Create generic labels 这里是创建通用标签,创建一个6*1的cell
P_labels = cell(num_of_points, 1);  % 6*1 cell% for循环把每一个指标打印到P_label这个变量中,这样P_label就存放了indicator中的6个指标
for ii = 1:num_of_points
%P_labels{ii} = sprintf('Label %i', ii);
P_labels{ii} = sprintf(indicator{ii});
end% Figure properties  绘制图窗,设置图窗特性
figure('units', 'normalized', 'outerposition', [0 0.05 1 0.95]);% Axes properties  这里设置轴间隔和小数精度
axes_interval = 2;
axes_precision = 3; % 保留三位小数% Spider plot 调用函数画图,后面的Marker、LineStyle这些是设置绘制的线条的特性
spider_plot(P, P_labels, axes_interval, axes_precision,...
'Marker', 'o',...
'LineStyle', '-',...
'LineWidth', 2,...
'MarkerSize', 6);% Title properties  这里设置雷达图的标题
title('不同方案特点对比',...
'Fontweight', 'bold',...
'FontSize', 12);% Legend properties  legend设定雷达图的图例,定义显示位置在图形外围、下方
legend('show',{'方案一','方案二','方案三','方案四'}, 'Location', 'southoutside');

   代码说明: 这个测试代码在 NewGuy012 的代码例子基础上改动了一下,具体含义上述代码已有详细注解。


Step3 : 实际效果


二、MATLAB导出可在Visio编辑的矢量图

2.1 操作简介

Step 1: 打开设置

   在运行出实际效果图之后不要关闭那个界面,点击 文件->导出设置

Step 2: 大小设置默认即可

tips: 之前看了一篇博客是通过计算算出来了长和宽,但是实际操作后发现会有错位,还是自动大小比较好。

Step 3: 渲染设置

导出为向量格式,dpi设置为300即可。

Step 4: 字体和线条设置

如果代码中设置了线条粗细,就不要再动线条的设置了,字体的设置可以根据需要设置,如果没有用到汉字想让别的字符美观,可以自定义字体名称,设置为 Times New Roman

Step 5: 导出为emf格式

只有导出emf格式才可以在Visio中灵活编辑,可以取消组合,单独编辑每一根线条,非常方便。

Step 6: 导入visio并编辑

打开Visio新建一个框图就行,直接把刚才导出的emf文件拖进去

如下动图所示:


Reference:

[1] https://vis.baidu.com/chartusage/radar/

[2] https://github.com/NewGuy012/spider_plot

[3] https://zhuanlan.zhihu.com/p/65116358

[4] https://ww2.mathworks.cn/matlabcentral/fileexchange/59561-spider_plot/


心有所期,全力以赴,定有所成! 加油吧

Author : 李光辉
date : Mon Jan 25 18:00:23 CST 2021
blog ID: Kevin_8_Lee
blog site : https://blog.csdn.net/Kevin_8_Lee

MATLAB绘制雷达图并导出矢量图到Visio编辑(论文用图)相关推荐

  1. MATLAB导出矢量图结合Visio或Adobe illustrator处理图片

    来源 使用matlab完成绘图后,希望直接导出矢量图供写作,而不是PNG等位图. 有些论文对图的数量还有限制,有时需要将多个图进行合并.虽然可以直接使用matlab,latex等进行合并,但感觉这两种 ...

  2. MATLAB绘制雷达图/蜘蛛图

    雷达图/蜘蛛图 雷达图(Radar Chart) 是以从同一点开始的轴上表示的三个或更多个定量变量的二维图表的形式显示多变量数据的图形方法.轴的相对位置和角度通常是无信息的. 雷达图也称为网络图,蜘蛛 ...

  3. AI绘图实战(十):制作线稿矢量图之包头巾的女人,画矢量图/生成矢量图/导出矢量图/直出svg/vector studio插件使用 | Stable Diffusion成为设计师生产力工具

    S:AI能取代设计师么? I :至少在设计行业,目前AI扮演的主要角色还是超级工具,要顶替?除非甲方对设计效果无所畏惧~~ 预先学习: 安装及其问题解决参考:<Windows安装Stable D ...

  4. 推荐一个开源免费的绘图软件 Draw.io 可导出矢量图

    问题描述 关于绘图,微软的 Visio 是一个不错的选择,但是不支持 mac 下使用,不支持 linux 桌面系统,而且是一个收费的软件. 推荐一个免费的软件,官网地址为 draw.io,先不急着下载 ...

  5. [译] 绘制路径:Android 中矢量图渲染

    原文地址:Draw a Path: Rendering Android VectorDrawables 原文作者:Nick Butcher 译文出自:掘金翻译计划 本文永久链接:github.com/ ...

  6. graphpad图片怎么导出矢量图_为何我的文章图片总是不满足杂志社要求?

    杂志社对于图片的要求往往十分严格,图片分辨率.图片大小.字体格式.颜色模式等等都会有要求,被拒了稿换一个杂志,可能又有一套新的要求,重复劳动让人苦不堪言.今天给大家分享一些SCI论文图片编辑过程中的小 ...

  7. ps 导出矢量图为svg,并上传iconfont

    ps 导出矢量图为svg, 并上传iconfont ps 矢量图形 设置为填充 关闭描边 合并的图形要合并图形组件 然后到出为svg

  8. 用Powerpoint (PPT)制作并导出矢量图、高分辨率图

    论文写作时经常需要导入矢量图,正规军都是用AI或者Inkscape作图,但是PPT更加适合小白用户,或者一些简单的构图需求使用PPT更加便捷,而且不得不承认PPT的某些功能是真的香,例如:简单的对齐. ...

  9. 【五一创作】Matlab 绘制风速、风向统计玫瑰花图【优化】

    在之前,有个博客专门讲matlab 绘制风速.风向统计玫瑰花图:这里面存在不少细节问题,目前对该部分代码做了优化.以前的博客链接见下: Matlab 绘制风速.风向统计玫瑰花图 最近接了一个任务,需要 ...

最新文章

  1. GC之七--gc日志分析工具
  2. 【youcans 的 OpenCV 例程 200 篇】102. 陷波带阻滤波器的传递函数
  3. 积跬步以至千里_“积跬步以至千里”——第三届世界老年旅游大会推进会昨日召开...
  4. ES6学习(新增字符串方法)
  5. 飞聊不可 · 上海技术招聘专场
  6. 互联网产品需求管理思考1——统一需求管理
  7. SumatraPDF安装包
  8. 直销模式系统开发|双轨制度跟级差制度哪个模式比较好?
  9. windows设置自动获取IP地址
  10. C语言普通字体转换花体 英文网名神器
  11. TCP三次握手第三次握手时ACK丢失怎么办
  12. conversational recommender system论文笔记;推荐系统(recommender system)+对话系统(dialogue system)
  13. MFC仿360屏幕截图
  14. IDEA 如何打开一个jsp文件?
  15. 台式计算机截图快捷键,电脑截屏的快捷键是什么
  16. Camtasia“喀秋莎”2022一款录屏神器
  17. 找不到该项目,请确认该项目的位置
  18. 实验七 函数程序设计 张玉生《C语言程序设计实训教程》双色版 配套实验书答案 (纯手打, 仅供参考)
  19. 基于单片机的点光源控制系统
  20. Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1)

热门文章

  1. 腾达路由器dns服务器未响应,荣耀猎人游戏路由怎么设置
  2. 2.12 二项式系数加法解 C实现
  3. Navicat迁移表数据 一
  4. Cocos2d-x的学习之旅(七)更新函数Update
  5. Facebook+S​kype
  6. 罗德里格旋转公式推导(自制)
  7. BLDC在3D风扇屏(全息风扇屏原理)上的应用----Trinamic(TMC)解决方案
  8. Github解除账号被封的方法
  9. (转)旅游拍照必读:10个经典人像摄影案例@『国家地理』
  10. 请问哪些好用文字转语音软件?