How to change the axis limits and remove/alter the ticks and labels for a COMPASS/POLAR plot?
39 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 25 de Abr. de 2013
Respondida: Abby Skofield
el 4 de Oct. de 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.
Respuesta aceptada
MathWorks Support Team
el 6 de Jun. de 2023
Editada: MathWorks Support Team
el 17 de Mayo de 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 comentarios
Más respuestas (2)
Adam Danz
el 30 de Mzo. de 2014
Editada: MathWorks Support Team
el 17 de Feb. de 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 comentarios
Abby Skofield
el 4 de Oct. de 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 comentarios
Ver también
Categorías
Más información sobre Polar Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!