フィルターのクリア

How to customise Polar Plots

11 ビュー (過去 30 日間)
Sam Hurrell
Sam Hurrell 2023 年 4 月 2 日
コメント済み: Star Strider 2023 年 4 月 6 日
I have data typically graphed as 'value (B) against angle (A)' as a plot (for angles -90 to 90) that I wish to graph as a polar plot. What command(s) can I write that'll graph this data with polar axes for angle as: -90 (on the left) to 90 (on the right) via 0 (below in the middle)?
  2 件のコメント
Star Strider
Star Strider 2023 年 4 月 2 日
Some detail is missing.
How do you want the tick labels to appear on the left side?
What do you want the top value (currently 180°) to be?
th = linspace(0, 2*pi, 360);
r = sin(2*th).^2;
figure
polarplot(th,r)
Ax = gca;
Ax.ThetaZeroLocation = 'bottom';
TTL = Ax.ThetaTickLabel
TTL = 12×1 cell array
{'0°' } {'30°' } {'60°' } {'90°' } {'120°'} {'150°'} {'180°'} {'210°'} {'240°'} {'270°'} {'300°'} {'330°'}
.
Sam Hurrell
Sam Hurrell 2023 年 4 月 4 日
Where you have 270 to 0 to 90, I want -90 to 0 to 90. I also want the top half of the graph gone leaving a semicircular polar plot.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2023 年 4 月 4 日
Try something like this —
th = linspace(0, 2*pi, 360);
r = exp(-0.1*th).*sin(2*th).^2;
figure
polarplot(th,r)
title('Original')
figure
polarplot(th+pi/2,r) % It May Be Necessary To Shift The Plot Phase (+90° Or +π/2) For This To Work Correctly
Ax = gca;
Ax.ThetaZeroLocation = 'bottom';
Ax.ThetaLim = [270 270+180];
Ax.ThetaTickLabel = compose('%d°',-90:30:90);
title('Shifted')
I needed to make my original function radially asymmetric to test this to be certain it would work correctly. It may be necessary for you to experiment with shifting the angles as well.
.
  3 件のコメント
Star Strider
Star Strider 2023 年 4 月 5 日
One small thing though, how do I set custom gridlines (every 15^o rather than every 30^o)?
Try this —
th = linspace(0, 2*pi, 360);
r = exp(-0.1*th).*sin(2*th).^2;
figure
polarplot(th,r)
title('Original')
figure
polarplot(th+pi/2,r) % It May Be Necessary To Shift The Plot Phase (+90° Or +π/2) For This To Work Correctly
Ax = gca;
Ax.ThetaZeroLocation = 'bottom';
Ax.ThetaLim = [270 270+180];
Ax.ThetaTick = Ax.ThetaLim(1) : 15 : Ax.ThetaLim(2);
Ax.ThetaTickLabel = compose('%d°',-90:15:90);
title('Shifted With Ticks Every 15°')
.
Star Strider
Star Strider 2023 年 4 月 6 日
If my Answer helped you solve your problem, please Accept it!
.

サインインしてコメントする。

その他の回答 (1 件)

the cyclist
the cyclist 2023 年 4 月 2 日
編集済み: the cyclist 2023 年 4 月 2 日
% Create plot
figure
theta = linspace(0,2*pi,25);
rho = 2*theta;
polarplot(theta,rho);
% Define a variable with the tick labels
thetaTickLabels = {'0°';'30°';'60°';'90°';'120°';'150°';'180°';'-150°';'-120°';'-90°';'-60°';'-30°'};
% Set theta how you want
set(gca,"ThetaZeroLocation","bottom", ...
"ThetaDir","counterclockwise", ...
"ThetaTickLabels",thetaTickLabels)
See the documentation for polarplot for details.
Note that while the axes are labeled in degrees, the default input is in radians. (That same page shows how to convert, if you need to.)
  1 件のコメント
Sam Hurrell
Sam Hurrell 2023 年 4 月 4 日
編集済み: Sam Hurrell 2023 年 4 月 4 日
That's really helpful thanks, but how do I edit it to remove the top half of the graph (-90, 180, 90) leaving a semi-circular plot?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by