2D polar plot axes & colour legend

hi
I'm a fairly new user to MATLAB2016b, and am struggling a bit with 2D polar plots.
I'd like to plot parameter values as a function of inclination (0-90deg) and azimuth (0-360deg) with the 'polar' function. In the polar plot, the radial direction reflects 0-90deg inclination and the tangential direction reflects 0-360deg (with 90deg towards the right).
For some reason the polar function adds a white rim to my figure, i.e. it plots data from 0-100 deg. Can anyone help me get rid of the 90-100 deg inclination section on the plot?
I'd also like to define the colourscale legend with a min and max value; how can that be done?
Attached is the polar plot code i'm using, where 'A' is the input value matrix. The 'A' is attached as an excel sheet, and A(1,1) is in cell 2B.
thanks for any help!
peter

 Accepted Answer

The matrix in the Excel file does not work with the code you posted (the matrix size is not compatible with the calculated values), so I cannot run it.
Use polarplot (introduced in R2016a, so you should have it) instead of polar. You can restrict the radial axis to the limits you set using the ‘RLim’ property of polarplot.
Example:
a = linspace(0, 2*pi);
r = linspace(0, pi);
figure
polarplot(a, r)
rlim([0, max(r)])
Experiment to get the result you want.

5 Comments

peter bautmans Answer moved here —
hi
Apologies i was not clear with my polar plot dataset. Attached is the data that should allow you to run the code.
With your help i've now managed to limit the radial extension from 0-90deg, but somehow i'm not plotting surfaces but individual lines. I can't seem to figure out what's wrong, maybe you can help?
thanks!
figure(1)
set(gca,'fontsize',16)
v=0:0.01:2.5;
[r,t] = meshgrid(0:5:90,0:5*pi/180:360*pi/180);
x = r.*cos(t);
y = r.*sin(t);
h = polarplot(x,y);
rlim([0,pi]);
figure(1)
set(gca,'fontsize',16)
v=0:0.01:2.5;
[r,t] = meshgrid(0:5:90,0:5*pi/180:360*pi/180);
x = r.*cos(t);
y = r.*sin(t);
h = polarplot(x,y);
rlim([0,90]);
view(90,-90)
hold on;
[c_bfm c_bfm]=contourf(x,y,A',v);
set(c_bfm,'LineStyle','none');
colorbar
set(colorbar,'FontSize',16)
hold on
for theta=0:30:330
hl=line([0 90*cosd(theta)],[0 90*sind(theta)]);
set(hl,'Color','k','LineWidth',0.5)
end
theta=0:5:360;
for rad=0:30:max(max(r))
plot(rad*cosd(theta),rad*sind(theta),'k','linewidth',0.5)
end
hold on;
polar%20plot.JPG
I am not sure what you want to do.
However if I am guessing correctly, based on the surface plot you attached originally, these lines alone appear to be what you want:
A = xlsread('polar plot data.xlsx');
figure(1)
set(gca,'fontsize',16)
v=0:0.01:2.5;
[r,t] = meshgrid(0:5:90,0:5*pi/180:360*pi/180);
x = r.*cos(t);
y = r.*sin(t);
h = polarplot(x,y);
rlim([0,pi]);
figure(2)
set(gca,'fontsize',16)
v=0:0.01:2.5;
[r,t] = meshgrid(0:5:90,0:5*pi/180:360*pi/180);
x = r.*cos(t);
y = r.*sin(t);
figure
[c_bfm, c_bfm]=contourf(x,y,A',v);
set(c_bfm,'LineStyle','none');
colorbar
set(colorbar,'FontSize',16)
axis equal
I slightly edited your code (I have no idea what the part I left our here is doing), however I made no actual changes to it.
peter bautmans Answer moved here —
hi - i want to make a surface polar plot with coloured surfaces according to the matrix cell values (as in my original post). My second post showed that your help solved my radial limits problem, but with that came a new problem: the coloured surface was replaced by unorganised lines. The solution you propose now puts a white square around the circular polar plot. I don't want that - the plot should resemble the first attached polar plot, but without the white rim. Any help would be mich appreciated - i obviously aren't very good at this!
Try this for figure(3):
figure(3)
[c_bfm, c_bfm]=contourf(x,y,A',v);
set(c_bfm,'LineStyle','none');
hold on
plot([zeros(1,13); 90*cosd(0:30:360)], [zeros(1,13); 90*sind(0:30:360)],'k')
plot(90*((0:0.33:1)'*cosd(0:10:360))', 90*((0:0.33:1)'*sind(0:10:360))','k')
colorbar
set(colorbar,'FontSize',16)
axis equal
set(gca, 'Box','off', 'XColor','none', 'YColor','none', 'Color','none')
hold off
producing:
I will let you add the radial tick values with the text function.
Adapt this to add them:
figure(3)
[c_bfm, c_bfm]=contourf(x,y,A',v);
set(c_bfm,'LineStyle','none');
hold on
plot([zeros(1,13); 90*cosd(0:30:360)], [zeros(1,13); 90*sind(0:30:360)],'k') % Plot Angle Radials
plot(90*((0:0.33:1)'*cosd(0:10:360))', 90*((0:0.33:1)'*sind(0:10:360))','k') % Plot Radius Circles
colorbar
cbpos = get(colorbar, 'Position');
set(colorbar,'FontSize',16, 'Position',cbpos+[0.05 0 0 0])
fpos = get(gcf, 'Position');
set(gcf, 'Position',fpos+[0 -100 200 100])
axis equal
set(gca, 'Box','off', 'XColor','none', 'YColor','none', 'Color','none')
hold off
xt = 105*cosd(0:30:330);
yt = 105*sind(0:30:330);
tlbls = sprintfc('%3d°', (0:30:330));
text(xt, yt, tlbls)
producing:
Experiment to get the result you want.
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!