How do I create circular patches within two radii?
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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
Walter Roberson
on 6 Oct 2015
I am not going to look at this until you clarify the difference with your new question http://uk.mathworks.com/matlabcentral/answers/247143-how-do-i-create-a-polar-plot-with-concentric-colored-rings-corresponding-to-single-values
(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.)
See Also
Categories
Find more on Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!