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

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.

Risposte (1)

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 Commenti

I thought of that too. But here is the issue I am having:
basically, I want to plot a radiation pattern that was exported from CST, a cut plane with ϕ = 0 and 180. So what CST does, it gives values of "realized gain" versus θ from 0 to 180, then after crossing 180 it get smaller until going to 0 back again on the other side (the image below shows how the data is stored). The issue here is, will Matlab register the absolute values of the ticks, or is it just an aesthetic modification? because for the plot to work, the "polar" (more like plane cut of sheprical) coordinates have to be actually going from 0 to 180 from both sides. In value not in appearance.
But anyway, I will be trying it now and I will let you know. Thanks a lot for your kind soul.
PS: notice in the picture how the angle theta goes up to 180 and the for the other half it continues its path alongside the decreasing angles, as I have shwn with the second picture in my first comment.
When your data increase to 180 and then decrease back to 0 such as [177 178 179 180 179 178], that line will not cross into the negative ticks in my answer. There can only be one 179, one 178, etc in the plot.
You can change the TickLabels which is just an aesthetic modification, if needed.
@Adam Danz sorry for spamming you btw.
So what you are saying is that such a configuration for axes is not possible?
Because if it is only aesthetic, the code will not care about it and just plot it in the positive range of θ, which would result in both halves beibg plotted in one half disk.
So here is a workaround I will be trying to test and I will let you know on the result:
1- I will modify the range of the values θ so that it will carry on and reach 360 at the end, which would necessiate modifying the text file.
2- I will plot the data and then use your suggestion to "mask" the ticks on the plot.
Thanks again Adam.
> 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);
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?

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by