Lisa
Lisa

Reputation: 13

Putting text on polar plot

I am using a polar plot and I want to have little squares moving around the plot. I am plotting those using the following command

h(1) = polar(handles.tab2_axes, testAngle, testRng, '-rs');
set( findobj(h(1), 'Type', 'line'), 'LineWidth',1, 'MarkerEdgeColor','r', ...
    'MarkerFaceColor','r', 'MarkerSize',16, 'annotation', text);

which plots a red square at the angle testAngle and the radius testRng. I am trying to have text above/below the square that follows the square depending on where it goes on the plot. Does anyone know an easy way of achieving this?

Upvotes: 1

Views: 6720

Answers (2)

user13049901
user13049901

Reputation: 11

At least for MatlabR2018a found out that the text should be specified directly in polar coordinates. For example: text(az_angle_in_radiance, r_distance, 'my text');

Upvotes: 1

Matt
Matt

Reputation: 13923

You can use the text-command to add annotations to your plot. Therefore you need to calculate actual x and y values from your testAngle and testRng.

The following code plots some points and assigns an individual text to them:

% to use your variable names
figure;
handles.tab2_axes = axes;

% create sample data
testAngle = [1, 2, 3, 4];
testRng   = [1, 2, 3, 4];
names     = {'object 1', 'object 2', 'object 3', 'object 4'};

% plot points
h(1) = polar(handles.tab2_axes, testAngle, testRng, '-rs');
set( findobj(h(1), 'Type', 'line'), 'LineWidth',1, 'MarkerEdgeColor','r', ...
    'MarkerFaceColor','r', 'MarkerSize',16);

% plot the labels
text(testRng.*cos(testAngle),testRng.*sin(testAngle),names,...
    'HorizontalAlignment','center',...
    'VerticalAlignment','bottom')

The result looks like this: result

Upvotes: 1

Related Questions