Mathematica中文论坛-非官方

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 9851|回复: 0

豆粑粑 matlab radarplot

[复制链接]

525

主题

594

帖子

2980

积分

金牌会员

Rank: 6Rank: 6

积分
2980
发表于 2018-2-19 15:29:53 | 显示全部楼层 |阅读模式
看着效果还不错。
其它的语言似乎都有直接用的函数,matlab,落后了。
修改一下别人的函数。挺好用。

fig_radplot.png
  1. clear all
  2. clc
  3. clf


  4. %% outline
  5. % test radarplot

  6. %% main
  7. % P=rand(13,2);
  8. % P(:,1)=P(:,1)*180/pi;
  9. % P(:,2)=20*P(:,2);
  10. % radarPlot(P)

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

  17. radarPlot(P, 'o-','LineWidth', 4, 'MarkerFaceColor', [0,0,0])
  18. % radarPlot(P, 'o-','LineWidth', 4)

  19. legend(pointNames{:}, 'Location', 'Best');
  20. title('Radar Plot Demo');
复制代码



  1. % RADARPLOT spiderweb or radar plot
  2. % radarPlot(P) Make a spiderweb or radar plot using the columns of P as datapoints.
  3. %  P is the dataset. The plot will contain M dimensions(or spiderweb stems)
  4. %  and N datapoints (which is also the number of columns in P). Returns the
  5. %  axes handle
  6. %
  7. % radarPlot(P, ..., lineProperties) specifies additional line properties to be
  8. % applied to the datapoint lines in the radar plot
  9. %
  10. % h = radarPlot(...) returns the handles to the line objects.
  11. function varargout = radarPlot( P, varargin )
  12. %
  13. % demo
  14. %%%%%%%%
  15. % nPoints = 4;
  16. % nDimensions = 6;
  17. % P = rand(nDimensions, nPoinhts);
  18. % P
  19. % pointNames = arrayfun( @(i)sprintf('p_{%d}', i),...
  20. % 1:nPoints, 'UniformOutput', false);
  21. %
  22. % radarPlot(P, 'o-','LineWidth', 3, 'MarkerFaceColor', [0,0,0])
  23. % legend(pointNames{:}, 'Location', 'Best');
  24. % title('Radar Plot Demo');
  25. %%%%%%%

  26. %%% Get the number of dimensions and points
  27. [M, N] = size(P);

  28. %%% Plot the axes
  29. % Radial offset per axis
  30. th = (2*pi/M)*(ones(2,1)*(M:-1:1));
  31. % Axis start and end
  32. r = [0;1]*ones(1,M);
  33. % Conversion to cartesian coordinates to plot using regular plot.
  34. [x,y] = pol2cart(th, r);
  35. hLine = line(x, y,...
  36.     'LineWidth', 1.5,...
  37.     'Color', [1, 1, 1]*0.7  );

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

  42. toggle = ~ishold;

  43. if toggle
  44.     hold on
  45. end

  46. %%% Plot axes isocurves
  47. n_cir=4;
  48. % Radial offset per axis
  49. th = (2*pi/M)*(ones(n_cir,1)*(M:-1:1));
  50. % Axis start and end
  51. r = (linspace(0.1, 0.9, n_cir)')*ones(1,M);
  52. % Conversion to cartesian coordinates to plot using regular plot.
  53. [x,y] = pol2cart(th, r);
  54. hLine = line([x, x(:,1)]', [y, y(:,1)]',...
  55.     'LineWidth', 1,...
  56.     'Color', [1, 1, 1]*0.5  );
  57. for i = 1:numel(hLine)
  58.     set(get(get(hLine(i),'Annotation'),'LegendInformation'),...
  59.         'IconDisplayStyle','off'); % Exclude line from legend
  60. end


  61. %%% Insert axis labels

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

  73. % Hold on to plot data points
  74. hold on

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

  79. % polar(Th, R)
  80. [X, Y] = pol2cart(Th, R);

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

  85. if toggle
  86.     hold off
  87. end

  88. if nargout > 0
  89.     varargout{1} = h;
  90. end
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|Mathematica中文论坛-非官方 ( 辽ICP备16001491号-1

GMT+8, 2024-3-28 18:14 , Processed in 0.121426 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表