【数据可视化】简单实现雷达图matlab

1.雷达图背景

1.1illustration

input
      n:表示输入信号具有 n 个属性,是标量,默认n = 6。
      signal_name:表示输入信号属性的名称,为一个1 × \times ×n 的元胞数组,默认为signal_name={‘one’,‘two’,‘three’,‘four’,‘five’,‘six’};。
output
      theta:各轴所在直角坐标系中的角度,为一个1 × \times ×n 矩阵。
原理: 本文提供的雷达图的绘制在直角坐标系下进行,首先隐藏直角系坐标轴,通过 n 计算出 theta ,然后使用 plot 函数将坐标轴绘制出来。
使用: ( 1 ) \left ( 1 \right ) (1)    > > \ \ > >   >> back_ground()      输出默认雷达图
            ( 2 ) \left ( 2 \right ) (2)    > > \ \ > >   >> theta=back_ground(n,signal_name)
                           输出相应的雷达图,得出各轴所在角度。
matlab代码:

function theta=back_ground(n,signal_name)
if nargin==0
    n=6;
    signal_name={'one','two','three','four','five','six'};
end
axis off
axis equal
hold on
theta_last=pi/2;
theta=zeros(n,1);
for i=1:n
    theta(i)=2*pi/n*i+pi/2;
    plot([0,5*cos(theta(i))],[0,5*sin(theta(i))],'k-','linewidth',2);
    [x,y] = pol2cart(theta(i),6);
    text(x,y,signal_name{i},'HorizontalAlignment','center')
    for j=1:5
        plot([j*cos(theta_last),j*cos(theta(i))],[j*sin(theta_last),j*sin(theta(i))],'--','linewidth',0.75,'color',[0.5,0.5,0.5]);
    end
    theta_last=theta(i);
end

1.2效果展示

雷达图

自定义: 可以通过修改 text 以及 plot 中的属性改变雷达图的外观。

2.数据可视化

2.1illustration

input
      theta:为 back_ground 函数的输出。
      data:表示输入信号各个属性的值,为一个1 × \times ×n 矩阵。
      color:输入信号使用某种颜色绘制。
matlab代码:

function spider(theta,data,color)
n=length(data);
[x_,y_] = pol2cart(theta(1),data(1));
for i=2:n
    th=theta(i);
    [x,y] = pol2cart(th,data(i));
    plot([x_,x],[y_,y],'-','linewidth',0.75,'color',color);
    hold on
    x_=x;
    y_=y;
end
[x,y] = pol2cart(theta(1),data(1));
plot([x_,x],[y_,y],'-','linewidth',0.75,'color',color);

2.2效果展示

example

x=[1,2,3,4,5;6,7,8,9,0;3,2,4,5,1;8,7,0,2,4];
signal_name={'QQ','微信','钉钉','支付宝','淘宝'};
[M,N]=size(x);
theta=back_ground(N,signal_name);
for i=1:M
    switch i
        case 1
            color='y';
        case 2
            color='m';
        case 3
            color='c';
        otherwise
            color='r';
    end
    spider(theta,x(i,:),color);
end

效果图

效果图

参考: https://blog.csdn.net/mt96mt96mt/article/details/80393030.

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值