zhanghouxing的个人博客分享 http://blog.sciencenet.cn/u/zhanghouxing

博文

matlab绘雷达图

已有 24036 次阅读 2014-9-17 22:14 |系统分类:科研笔记| MATLAB, 雷达图

今天主要用matlab画了一张雷达图,效果如下,如果你对这种类型的图,不感兴趣,请跳过。

这张图的原型是用Polar这个函数,但是这个函数画出来的图不能实现上面的效果,也不能通过参数实现。因此这时候就必须对Polar这个函数进行修改。首先,对圆环里面的几条射线直接的夹角进行修改(为了保证polar原始文件不被修改,我将文件另存为myploar):

% plot spokes
   th = (1:6)*2*pi/12;
   cst = cos(th); snt = sin(th);
   cs = [-cst; cst];
   sn = [-snt; snt];
   line(rmax*cs,rmax*sn,'linestyle',ls,'color',tc,'linewidth',1,...
        'handlevisibility','off','parent',cax)



修改之后:


th = (1:5)*2*pi/10; %定义射线之间的夹角,这里定义为36°,因此会出现10条射线
   cst = cos(th); %横坐标
   snt = sin(th); %纵坐标

% 去掉五条射线,只保留5条射线。
   cs = [[-cos(pi/5),0,-cos(3*pi/5),0,-cos(pi)];[0,cos(2*pi/5),0,cos(4*pi/5),0]];
   sn = [[-sin(pi/5),0,-sin(3*pi/5),0,-sin(pi)]; [0,sin(2*pi/5),0,sin(4*pi/5),0]];
   line(rmax*cs,rmax*sn,'linestyle',ls,'color',tc,'linewidth',1,...
        'handlevisibility','off','parent',cax)


然后就是绘图了,以我的数据为例,代码如下:


clc;
clear;
x=[0:2*pi/5:2*pi];
data=[28.8635,67.529,41.042,341.604,137.4345,28.8635;17.1815,71.161,48.0315,343.9165,136.374,17.1815;29.1675,70.097,49.867,328.3965,149.13,29.1675;...
   99.945,52.5665,17.0975,309.75,169.6095,99.945;52.674,72.3005,68.434,281.5955,193.409,52.674];
for i=1:5
mypolar(x,data(i,:));
hold on
end


这样汇出来的图,在圆环最外围还存在一圈数字,这是对每条射线的注释,因此,还需要将mypolar下对应的代码去掉,去掉代码如下:



% annotate spokes in degrees
  % rt = 1.1*rmax;
 %  for i = 1:length(th)
 %      text(rt*cst(i),rt*snt(i),int2str(i*36),...
 %           'horizontalalignment','center',...
 %           'handlevisibility','off','parent',cax);
 %     if i == length(th)
%           loc = int2str(0);
 %      else
 %          loc = int2str(180+i*36);
 %      end
 %      text(-rt*cst(i),-rt*snt(i),loc,'horizontalalignment','center',...
%            'handlevisibility','off','parent',cax)
%  end


这样,图的基本框架就搭建了,然后就是插入文本框,对每条射线进行注释;添加legend。最后达到上述效果。




 




https://blog.sciencenet.cn/blog-922140-828597.html

上一篇:利用Github免费搭建个人网站详解
下一篇:endnote使用的两个问题
收藏 IP: 210.77.68.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-18 12:32

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部