Rick T
Rick T

Reputation: 3389

Changing compass axis in MATLAB and Octave

I am using the compass plot function using octave 3.8.1 Linux to plot a circular data set but I have difficulties changing the axis of this plot.

Specifically, I would like to remove some of the axis points (say for example the 30 and 60 degrees) and also I would like to change numbers (for example instead of 90 write 30).

Does anyone have an idea of how this can be done?


Example of code: Along with image it produces

%compass plot
clear all,clc
x_angle=[45,90,123,43,53,23,53,12];
y_amp=[1,.5,.4,.1,.6,.3,.7,.3]; 
[x_cart,y_cart]=pol2cart([x_angle-180]*pi/180,y_amp);
h = compass(x_cart,y_cart);

for k = 1:length(x_cart)
    a_x = get(h(k), 'xdata'); 
    b_y = get(h(k), 'ydata'); 
    %//To delete the arrows you need to delete all but the first two entries 
    %//in the xdata and ydata fields of the plot. The color can be changed 
    %//by setting the color property. Please find below a solution for 
    %//compass plots with arbitrary numbers of arrows.
    set(h(k), 'xdata', a_x(1:2), 'ydata', b_y(1:2), 'color', 'r')
end;

Compass Plot

Upvotes: 1

Views: 1027

Answers (1)

rayryeng
rayryeng

Reputation: 104493

This is a hack as compass plots are a bit different than what I'm used to, but we can do this:

Removing a label

You can use the findall command using the current figure in focus (which is your compass plot), and replace all of those strings you don't want to the blank string. In other words, if you want to remove all of those instances that have 30 or 60 in your plot, you can do this:

set(findall(gcf, 'String', '30', '-or', 'String', '60') ,'String', '  ');

What this is saying is that you want to set your figure so that we find any string that has 30 or 60 and replace them with the blank string. Notice that there are two spaces in the blank string as the last parameter of set. Using a single space doesn't work. If you just want to do one label at a time, you can do:

set(findall(gcf, 'String', '30'), 'String', '  ');
set(findall(gcf, 'String', '60'), 'String', '  ');

Modifying a label

We can still use the same syntax above. However, instead of doing the blank string, replace it with a string of your choosing. For your example, you want to change the label from 90 to 30. As such:

set(findall(gcf, 'String', '90'), 'String', '30');

One good thing to note is that the numbers are strings. Setting them as actual numbers won't do anything.


Hope this helps! BTW, great job on producing a reproducible example. It allowed me to test this easily.

Upvotes: 2

Related Questions