How to change the axis limits and remove/alter the ticks and labels for a COMPASS/POLAR plot?

37 views (last 30 days)
I would like to change the axes properties of a compass plot within the code without using the manual plotting edit tool.
For instance, I would like to:
1) Set the magnitude of the axis to a certain maximum number no matter what the data is that I am plotting.
2) Change the rotational axis labels.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 6 Jun 2023
Edited: MathWorks Support Team on 17 May 2023
Starting in MATLAB R2016a, there is a "polarplot" function that allows you to update the properties of the polar axes. Please see the following documentation pages for reference.
The ability to change the axis limits, ticks and labels for a compass or polar plot is not available previous releases.  The following workaround were tested in MATLAB R2010b.
1) Changing the axis limits:
If (x,y) is the data to be plotted and the maximum axis limit is max_lim:
x = [1;3;-2];
y = [-3;-2;1];
% Original compass figure
figure;
compass(x,y);
% Modified compass figure with higher radial limit
figure;
max_lim = 10;
x_fake=[0 max_lim 0 -max_lim];
y_fake=[max_lim 0 -max_lim 0];
h_fake=compass(x_fake,y_fake);
hold on;
h=compass(x,y);
set(h_fake,'Visible','off');
Please note that depending on the value of "max_lim", the actual limit may not be exact. For example, setting "max_lim = 0.14" will produce a axis limit of "0.15". The reason this happens is because the axis automatically rounds the limit to the nearest next minor grid. If this is not sufficiently close for your application, you may try manually changing the tick labels of the radial axis to give the correct appearance. Note that this will require you to adjust your data so the plot makes sense.
2) Removing/altering the degree-tick labels:
% Using the code above
% Removing the label
set(findall(gcf, 'String', '30', '-or','String','60') ,'String', ' ');
% Altering the angular label
set(findall(gcf, 'String', '0'),'String', ' Zero');
% Altering the radial label
set(findall(gcf, 'String', ' 4'),'String', ' Four');
Notice that in order to change radial ticks two additional spaces are required in the call to "findall" to find the radial strings. In other words, although the radial string appears to be "4", in reality the string is " 4".

More Answers (2)

Adam Danz
Adam Danz on 30 Mar 2014
Edited: MathWorks Support Team on 17 Feb 2021
Hello all, I had a similar issue using polar plots so I wrote a code that does the trick. https://www.mathworks.com/matlabcentral/fileexchange/46087-polarticks-m
After creating your polar plot, you can run this code to adjust the circumference intervals and tickmarks. For example,
p = polar (deg2rad([25, 25]), [0, 33])
h = polarticks(8, p)
This will remove all radii and ticks and replace them with 8 equally spaced intervals (ie, 45 deg). See description within code for more details.
Adam

Abby Skofield
Abby Skofield on 4 Oct 2024
Starting in R2024b, the compassplot function can be used in place of compass to create arrows eminating from the origin of a polar axes. The PolarAxes class has many properties and several functions you can use to customize its appearance. Note that compassplot can be combined in a PolarAxes with other plots like polarhistogram, polarplot, polarscatter, etc.
t = linspace(pi/3,2*pi,10);
cp = compassplot(t,sin(t)) % new in R2024b
cp =
PolarCompassPlot with properties: Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 ThetaData: [1.0472 1.6290 2.2108 2.7925 3.3743 3.9561 4.5379 5.1196 5.7014 6.2832] RData: [0.8660 0.9983 0.8021 0.3420 -0.2306 -0.7274 -0.9848 -0.9182 -0.5495 -2.4493e-16] Use GET to show all properties
pax = gca % get a handle to the PolarAxes
pax =
PolarAxes with properties: ThetaLim: [0 360] RLim: [0 1] ThetaAxisUnits: 'degrees' ThetaDir: 'counterclockwise' ThetaZeroLocation: 'right' Use GET to show all properties
% Set the radial axis limits.
pax.RLim = [ 0 2 ];
% Customize the tick values and tick labels.
thetaticks( [0 90 180 270]);
thetaticklabels(["East","North","West","South"])

Categories

Find more on Polar Plots in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2010b

Community Treasure Hunt

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

Start Hunting!