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

55 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 24 Apr 2019
Edited: MathWorks Support Team on 24 Apr 2019
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".
  1 Comment
Karen Bemis
Karen Bemis on 6 Dec 2019
This is totally useless ... polarplot does not do arrows like the compass plot.
Nor will the string search work to completely relabel 0-360 to go the other way around -- at some point there will be duplicate answers of which you want to change one and keep the other.

Sign in to comment.

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

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!