How do I create circular patches within two radii?

4 views (last 30 days)
I am trying to create a polar plot with circular rings of constant values. I am able to create the patches, but do not know how to 'constrain' the colored values to the area between two radii. This is what I have so far - this is just a sample and does not contain any real values. I'm just trying to figure out how to code this right now.
Arbitrary values below. The colorbar values are set to be ranging from 0-40, and the two patch cdata values are set at 28 and 35.
numPoints=100;
radius=100;
theta=linspace(0,2*pi,numPoints);
rho=ones(1,numPoints)*radius;
[X,Y] = pol2cart(theta,rho);
radius=20;
rho=ones(1,numPoints)*radius;
[X,Y] = pol2cart(theta,rho);
H=patch(X,Y,1);
set(gca,'CLim',[0 40])
cdata = ones(1,100)*28;
set(H,'FaceColor','interp',...
'CData',cdata,...
'CDataMapping','scaled',...
'EdgeColor','interp',...
'LineWidth',5)
colormap(jet)
hold on
radius=10;
rho=ones(1,numPoints)*radius;
[X,Y] = pol2cart(theta,rho);
H=patch(X,Y,1);
cdata = ones(1,100)*35;
set(H,'FaceColor','interp',...
'CData',cdata,...
'CDataMapping','scaled',...
'EdgeColor','interp',...
'LineWidth',5)
What this is doing is just writing over the first patch with the second, smaller patch. Because of this, there is no interpolation between them.

Answers (1)

Walter Roberson
Walter Roberson on 5 Oct 2015
Edited: Walter Roberson on 5 Oct 2015
numPoints = 100;
numrings = 5;
cmap = jet(numrings);
radius = linspace(0,200,numrings+1); %where the rings are to be drawn
theta = linspace(0,2*pi,numPoints);
[THETA,RADIUS] = ndgrid(theta,radius);
[X,Y] = pol2cart(THETA,RADIUS);
for K = 1 : numrings
xpoints = [X(:,K); flipud(X(:,K+1))];
ypoints = [Y(:,K); flipud(Y(:,K+1))];
patch(xpoints, ypoints, cmap(K,:), 'EdgeColor', 'none');
hold on
end
hold off
Defining the circle with radius 0 to get the first ring makes the code simpler but you could do without it if you treated the ring at the origin differently. And this code works immediately if you use a lower bound that is not 0, if you want the first colored ring to start at a distance from the origin.
  4 Comments
AMart
AMart on 6 Oct 2015
Yes, that is exactly what I'm trying to create. My problem is that I have a multitude of data points scattered around the center of my plots, so simply running a linear interpolation creates a lot of noise due to distance weighting, etc. If you have advice on a better way to complete this, it would be awesome. Thanks.
Walter Roberson
Walter Roberson on 6 Oct 2015
(Remember, if I do not answer immediately it might be because I am working on someone else's question, or I might be at an appointment, or I might be sleeping, or I might be ill, or I might be cooking, or otherwise engaged in Life.)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!