如何使用与Matlab中的单个值对应的同心彩色环创建极坐标图?

时间:2015-10-06 20:55:56

标签: matlab contour

我正在尝试创建一个看起来像这样的图,其中常量值(颜色)的环从0到100以10个单位为增量延伸。

Rings of single values extending outward from center

然而,我的代码并没有产生这个,我不知道它出了什么问题。

   % values representing the colors that each ring should be 
   % starting from the center and moving outwards in 10 unit increments.

   values = [364,358,354,348,339,335,330,325,320,310];

   xCoord = linspace(0,2*pi,10);
   yCoord = linspace(0,100,10);
   [TH,R] = meshgrid(xCoord,yCoord);
   [X,Y] = pol2cart(TH,R);
   [Z] = meshgrid(values);
   contour_ticks = 300:5:375;
   figure
   hold on
   contourf(X,Y,Z,contour_ticks);
   a=gca; cb=colorbar; colormap('jet'); caxis([300 375]);

这会产生类似于此的情节:

Incorrect plot

任何想法我做错了什么?任何帮助是极大的赞赏。感谢。

1 个答案:

答案 0 :(得分:2)

如果您只想绘制圆圈,可以使用以下方法:

radii = 100:-10:10; %// descending order, so that bigger circles don't cover small ones
colors = parula(numel(radii)); %// or use some other colormap
for n = 1:numel(radii)
    r = radii(n);
    rectangle('Position', [-r -r 2*r 2*r], 'Curvature', [1 1], 'FaceColor', colors(n,:),...
       'EdgeColor', 'none') %// plot each circle using sequential colors, no edge
    hold on
end
axis equal
axis([-1 1 -1 1]*max(radii))

enter image description here