meatball1982 发表于 2018-2-19 15:29:53

豆粑粑 matlab radarplot

看着效果还不错。
其它的语言似乎都有直接用的函数,matlab,落后了。
修改一下别人的函数。挺好用。


clear all
clc
clf


%% outline
% test radarplot

%% main
% P=rand(13,2);
% P(:,1)=P(:,1)*180/pi;
% P(:,2)=20*P(:,2);
% radarPlot(P)

nPoints = 4;
nDimensions = 6;
P = rand(nDimensions, nPoints);
P
pointNames = arrayfun( @(i)sprintf('p_{%d}', i),...
1:nPoints, 'UniformOutput', false);

radarPlot(P, 'o-','LineWidth', 4, 'MarkerFaceColor', )
% radarPlot(P, 'o-','LineWidth', 4)

legend(pointNames{:}, 'Location', 'Best');
title('Radar Plot Demo');



% RADARPLOT spiderweb or radar plot
% radarPlot(P) Make a spiderweb or radar plot using the columns of P as datapoints.
%P is the dataset. The plot will contain M dimensions(or spiderweb stems)
%and N datapoints (which is also the number of columns in P). Returns the
%axes handle
%
% radarPlot(P, ..., lineProperties) specifies additional line properties to be
% applied to the datapoint lines in the radar plot
%
% h = radarPlot(...) returns the handles to the line objects.
function varargout = radarPlot( P, varargin )
%
% demo
%%%%%%%%
% nPoints = 4;
% nDimensions = 6;
% P = rand(nDimensions, nPoinhts);
% P
% pointNames = arrayfun( @(i)sprintf('p_{%d}', i),...
% 1:nPoints, 'UniformOutput', false);
%
% radarPlot(P, 'o-','LineWidth', 3, 'MarkerFaceColor', )
% legend(pointNames{:}, 'Location', 'Best');
% title('Radar Plot Demo');
%%%%%%%

%%% Get the number of dimensions and points
= size(P);

%%% Plot the axes
% Radial offset per axis
th = (2*pi/M)*(ones(2,1)*(M:-1:1));
% Axis start and end
r = *ones(1,M);
% Conversion to cartesian coordinates to plot using regular plot.
= pol2cart(th, r);
hLine = line(x, y,...
    'LineWidth', 1.5,...
    'Color', *0.7);

for i = 1:numel(hLine)
    set(get(get(hLine(i),'Annotation'),'LegendInformation'),...
      'IconDisplayStyle','off'); % Exclude line from legend
end

toggle = ~ishold;

if toggle
    hold on
end

%%% Plot axes isocurves
n_cir=4;
% Radial offset per axis
th = (2*pi/M)*(ones(n_cir,1)*(M:-1:1));
% Axis start and end
r = (linspace(0.1, 0.9, n_cir)')*ones(1,M);
% Conversion to cartesian coordinates to plot using regular plot.
= pol2cart(th, r);
hLine = line(', ',...
    'LineWidth', 1,...
    'Color', *0.5);
for i = 1:numel(hLine)
    set(get(get(hLine(i),'Annotation'),'LegendInformation'),...
      'IconDisplayStyle','off'); % Exclude line from legend
end


%%% Insert axis labels

% Compute minimum and maximum per axis
minV = min(P,[],2);
maxV = max(P,[],2);
for j = 1:M
    % Generate the axis label
    msg = sprintf('x_{%d} = %5.2f ... %5.2f',...
      j, minV(j), maxV(j));
    = pol2cart( th(1, j), 1.1);
    text(mx, my, msg);
end
axis([-1,1,-1,1]*1.5)

% Hold on to plot data points
hold on

% Radius
R = 0.8*((P - (minV*ones(1,N)))./((maxV-minV)*ones(1,N))) + 0.1;
R = ;
Th = (2*pi/M) * ((M:-1:0)'*ones(1,N));

% polar(Th, R)
= pol2cart(Th, R);

h = plot(X, Y, varargin{:});
axis([-1,1,-1,1])
axis square
axis off

if toggle
    hold off
end

if nargout > 0
    varargout{1} = h;
end


页: [1]
查看完整版本: 豆粑粑 matlab radarplot