How to plot a polar plot with theta limited to 180 degrees on both ways

조회 수: 62 (최근 30일)
Abdennaser Hadab
Abdennaser Hadab 2022년 10월 18일
댓글: Abdennaser Hadab 2022년 10월 20일
Hello everyone and thank you for your supportive community.
I have got one issue with polar plots: I am trying to draw a farfield pattern projected onto a "polar" plane (will explain why I put it into quotation marks later). The issue is, in Matlab, the angle θ goes from 0 to 360 degrees. While for the farfield plane cut, we are dealing with spherical coordinates where θ goes from 0 to 180 and ϕ from 0 to 360 (as per the definition of spherical coordinates). Because a cut, in this case, is made by fixing the angle ϕ at given angle (let it be 0 for instance), and then running the angle θ from 0 to 180, then taking the symmetrical ϕ (basically flipping around the axis, or adding 180 degrees), and running θ again from 0 to 180. Basically, the first run gives us half a circle, and the second the second symmetric half.
What I have found to be able to get in matlab is the following figure:
Whereas what I am looking for is something like this:
I realize that in matlab you can change the tick format to 180 which gives one half with θ goes from 0 to 180 and the other half with θ from 0 to -180. But that is not what is explicited in the second figure.
Thanks once again for anyone helping people figure things out.

답변 (1개)

Adam Danz
Adam Danz 2022년 10월 20일
Set the ThetaLim and ThetaZeroLocation properties of polaraxes.
See polaraxes properties for more info.
If the negative theta tick values are not desired, you can set the ThetaTickLabels to the absolute value of the current ticks values.
theta = linspace(0,6*pi);
rho1 = theta/10;
ax = polaraxes();
polarplot(ax, -pi:pi/4:pi, 1:9)
ax.ThetaLim = [-180,180];
ax.ThetaZeroLocation = 'top';
  댓글 수: 5
Adam Danz
Adam Danz 2022년 10월 20일
> So what you are saying is that such a configuration for axes is not possible?
For axis ticks, yes. You can't have duplicate ticks and ticks must be sorted.
However, you can set TickLabels to whatever you want.
Your plan sounds good. Alternatively, instead of using theta data in the range of [0,360], you could use [-180,180] as in my example. Then, when you change the tick labels you just need to apply abs() on the ticks.
Example:
theta = linspace(0,6*pi);
rho1 = theta/10;
ax = polaraxes();
polarplot(ax, -pi:pi/4:pi, 1:9)
ax.ThetaLim = [-180,180];
ax.ThetaZeroLocation = 'top';
ax.ThetaTick = [-180:30:180];
ax.ThetaTickLabels = abs(ax.ThetaTick);
Abdennaser Hadab
Abdennaser Hadab 2022년 10월 20일
Thanks once again @Adam Danz.
Though, it does not seem to work with my data: instead of theta and rho1 as you have given them; I have two tables that are supposed to represent my radiation pattern. But when I plot them one versus the other I get the following figure:
when normally it should look like double the first image I posted. Any idea what I got wrong?
PS: what I did was the following in Matlab:
table=readtable('E:\Actual\Bruce array\Exported data\farfield2791.txt');
theta_table = table(:,1);
phi_table = table(:,2);
mag_table = table(:,3);
theta = table2array(theta_table);
phi = table2array(phi_table);
rho1 = table2array(mag_table);
%patternCustom(mag,theta,phi,'CoordinateSystem','polar','Slice','phi','SliceValue',0);
ax = polaraxes();
polarplot(ax, theta, rho1)
ax.ThetaLim = [-180,180];
ax.ThetaZeroLocation = 'top';
ax.ThetaTick = [-180:15:180];
ax.ThetaTickLabels = abs(ax.ThetaTick);
the table is made of 8 columns, the first is θ, the second is ϕ and the third is the amplitude I am trying to plot. Any ideas what I could have done wrong?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by