# Can you plot polarplots so that theta zero location is at any arbitrary angle or are top left bottom right the only options?

28 Ansichten (letzte 30 Tage)
Ryan Rose am 28 Sep. 2020
Bearbeitet: Adam Danz am 29 Sep. 2020
I would like to plot a polar plot so that the top angle is the heading of a vehicle like you would see in a navigation display. Is there a way to do this? I tried using the view function to change the angle but it failed. Is there a way to change ax.ThetaZeroLocation to an angle instead of the four options listed?
##### 1 KommentarKeine anzeigenKeine ausblenden
Ryan Rose am 28 Sep. 2020
reference for what I'd like to try to do with the axis. https://i.stack.imgur.com/OqIG8.jpg

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Adam Danz am 28 Sep. 2020
Bearbeitet: Adam Danz am 29 Sep. 2020
Here's a demo showing how to rotate line objects and theta ticks on polar axes. The orientation of the polar axes is controlled by a uislider within a UIFigure. The slider's callback function updates the "ThetaData" property for all objects on the axes.
Restrictions and notes of caution:
1. If there are any plotted objects whose angular positions are not controlled by the "ThetaData" property (ie, text objects), this will have to be adapted to work with their positional properties.
2. Since the ThetaData values are updated for all objects, they will no longer retain their original values. For example, if the original theta value was 0 and it was rotated by 15 deg, then its new theta value will be 15. To get the original theta values back, see the slider's UserData property which stores the current orientation of the polar axes relative to the ThetaZeroLocation.
% Create data for polar plot
th1 = linspace(0,pi*11/6,12);
r1 = cos(th1);
th2 = linspace(5*pi/6,9*pi/6,20);
r2 = linspace(1,.1,20);
% Create the polar plot
% For this demo, this plot can only contain objects whose
% angular position is controlled by the 'ThetaData' property.
fig = uifigure();
ax = polaraxes(fig);
hold(ax,'on')
polarplot(ax, th1, r1, 'b-','LineWidth',2);
polarplot(ax, th2, r2, 'ro','MarkerFaceColor', 'r');
polarplot(ax, 0, .9, 'kp', 'MarkerSize', 16, 'MarkerFaceColor', 'y')
titleHandle = title(ax,'Orientation: 0 deg');
ax.Position([2,4]) = ax.Position([2,4])+[.15,-.15];
uilabel(fig, 'position', [20 60, 400,20], 'Text', 'Adjust orientation of polar axes (deg from ThetaZeroLocation)');
% You can substitute "ValueChangingFcn" and "ValueChangedFcn" for the same callback function.
sldr = uislider(fig, 'Position', [20, 50, 520, 3], 'Value', 0, 'Limits', [-180,180],...
'MajorTicks', -180:30:180, 'MinorTicks', [], 'UserData', 0, ... % UserData stores current rotation
'ValueChangingFcn', @(sldr,event)updatePolarTicks(sldr,event,ax,titleHandle));
drawnow(); pause(0.05)
% Define slider's callback function to update the orientation of the polar axes
% relative to the TheatZeroLocation.
function updatePolarTicks(sldr,event,ax,titleHandle)
% Update title and compute rotation amount; store new orientation in memory.
titleHandle.String = sprintf('Orientation: %.0f deg', event.Value);
rotation = event.Value - sldr.UserData; %(+=CCW, -=CW)
sldr.UserData = event.Value;
% Convert rotation angle to radians, wrapped to [0,2pi]
dwrap = @(d)mod(d,360) + (d>0 & mod(d,360)==0).*360; %wrap degrees to 0:360
deg = dwrap(rotation);
% Rotate line objects
chil = ax.Children;
% Update ticks
origTickLabs = ax.ThetaTickLabel;
[newTicks, tickLabIdx] = unique(dwrap(unique(mod(ax.ThetaTick,360),'stable') + deg));
ax.ThetaTick = newTicks;
ax.ThetaTickLabel = origTickLabs(tickLabIdx);
end
##### 5 Kommentare4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden
Adam Danz am 29 Sep. 2020
Bearbeitet: Adam Danz am 29 Sep. 2020
Ryan, if you want to recreate the radio magnetic indicator (or whatever it is) in the image you shared, you can fairly easily overlay the outline of an aircraft using image, imagesc, or imshow, after scaling it properly and you can also replace the ThetaTickLabels with compass directions ('N', 'E', etc..) which will be maintained as the polar axes are rotated.

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Sindar am 28 Sep. 2020
something like this:
top_angle = 24;
% get current labels
tt = thetaticks;
% rotate angles so top_angle takes place of 90
tt_2 = mod(tt - 90 + top_angle,360);
thetaticklabels(tt_2)
##### 2 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Sindar am 28 Sep. 2020
yeah, it only changes the axis labels without rotating the data

Melden Sie sich an, um zu kommentieren.

### Kategorien

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!

Translated by