How to change the axis limits and remove/alter the ticks and labels for a COMPASS/POLAR plot?
39 views (last 30 days)
Show older comments
MathWorks Support Team
on 25 Apr 2013
Answered: Abby Skofield
on 4 Oct 2024
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
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".
0 Comments
More Answers (2)
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
0 Comments
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
pax = gca % get a handle to the PolarAxes
% 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"])
0 Comments
See Also
Categories
Find more on Polar Plots 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!