How to adjust the position of the x-axis ticks and put the angle degree on the values of the x-axis ticks?
9 views (last 30 days)
Show older comments
Haitham AL Satai
on 4 Oct 2022
Commented: Haitham AL Satai
on 5 Oct 2022
Dears, I have the following plot in Matlab as shown below:
The x-axis represents angles. I would like to add the angle degree, which is the small circle on the x-axis ticks, and I need to distribute the values of the x-axis elegantly, not, as shown above, they are close to each other. Any assistance, please?
Vec_MIS = [0.238000000000000,1.18980000000000,2.14160000000000,4.99700000000000,6.90070000000000,10.7079000000000,14.5152000000000,16.8947000000000,23.3195000000000,28.7924000000000,34.5033000000000,42.1178000000000];
Vec_BEAM = [113.265900000000,117.549100000000,117.549100000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000];
Vec_NOBEAM = [0.238000000000000,1.18980000000000,2.14160000000000,4.99700000000000,4.99700000000000,8.80430000000000,10.7079000000000,14.5152000000000,16.4188000000000,19.2742000000000,21.1779000000000,23.5574000000000];
ThetaHalf = [5,10,15,20,25,30,35,40,45,50,55,60];
figure
semilogx(ThetaHalf,Vec_BEAM,'-dg',ThetaHalf,Vec_NOBEAM,'-^r',ThetaHalf,Vec_MIS,'-Oc','LineWidth',2,'MarkerEdgeColor','b')
xticks(ThetaHalf)
xlabel('\theta_1_/_2');
ylabel('Coverage area m^2');
legend('With Beam','Without Beam','Manual')
grid on;
0 Comments
Accepted Answer
Les Beckham
on 4 Oct 2022
Edited: Les Beckham
on 4 Oct 2022
Vec_MIS = [0.238000000000000,1.18980000000000,2.14160000000000,4.99700000000000,6.90070000000000,10.7079000000000,14.5152000000000,16.8947000000000,23.3195000000000,28.7924000000000,34.5033000000000,42.1178000000000];
Vec_BEAM = [113.265900000000,117.549100000000,117.549100000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000];
Vec_NOBEAM = [0.238000000000000,1.18980000000000,2.14160000000000,4.99700000000000,4.99700000000000,8.80430000000000,10.7079000000000,14.5152000000000,16.4188000000000,19.2742000000000,21.1779000000000,23.5574000000000];
ThetaHalf = [5,10,15,20,25,30,35,40,45,50,55,60];
figure
% Use plot instead of semilogx to avoid the "scrunching" of the x axis
% semilogx(ThetaHalf,Vec_BEAM,'-dg',ThetaHalf,Vec_NOBEAM,'-^r',ThetaHalf,Vec_MIS,'-Oc','LineWidth',2,'MarkerEdgeColor','b')
plot(ThetaHalf,Vec_BEAM,'-dg',ThetaHalf,Vec_NOBEAM,'-^r',ThetaHalf,Vec_MIS,'-Oc','LineWidth',2,'MarkerEdgeColor','b')
xticks(ThetaHalf)
xlabel('\theta_1_/_2');
ylabel('Coverage area m^2');
legend('With Beam','Without Beam','Manual')
grid on;
xticklabels(compose('%d°', ThetaHalf)) % set x tick labels to include degree symbol
2 Comments
More Answers (1)
dpb
on 4 Oct 2022
With all values in one decade, log plot gets pretty squished; you can set the xlim to just cover the actual range and then only use some of the x values as ticks instead of all.
But, switching to linear axis may be as good or better a solution unless there's some unstated reason for the log axis; I've shown both on two subplots; take your pick...
Vec_MIS = [0.238000000000000,1.18980000000000,2.14160000000000,4.99700000000000,6.90070000000000,10.7079000000000,14.5152000000000,16.8947000000000,23.3195000000000,28.7924000000000,34.5033000000000,42.1178000000000];
Vec_BEAM = [113.265900000000,117.549100000000,117.549100000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000,117.787000000000];
Vec_NOBEAM = [0.238000000000000,1.18980000000000,2.14160000000000,4.99700000000000,4.99700000000000,8.80430000000000,10.7079000000000,14.5152000000000,16.4188000000000,19.2742000000000,21.1779000000000,23.5574000000000];
ThetaHalf = [5,10,15,20,25,30,35,40,45,50,55,60];
subplot(2,1,1)
semilogx(ThetaHalf,Vec_BEAM,'-dg',ThetaHalf,Vec_NOBEAM,'-^r',ThetaHalf,Vec_MIS,'-Oc','LineWidth',2,'MarkerEdgeColor','b')
ixLab=[1:6 8:2:numel(ThetaHalf)];
xticks(ThetaHalf(ixLab))
xticklabels(ThetaHalf(ixLab)+"^{\circ}")
xlim([ThetaHalf(1) ThetaHalf(end)])
xlabel('\theta_1_/_2');
ylabel('Coverage area m^2');
legend('With Beam','Without Beam','Manual')
grid on;
subplot(2,1,2)
plot(ThetaHalf,Vec_BEAM,'-dg',ThetaHalf,Vec_NOBEAM,'-^r',ThetaHalf,Vec_MIS,'-Oc','LineWidth',2,'MarkerEdgeColor','b')
xticks(ThetaHalf)
ixLab=[1:numel(xticks)];
xticklabels(ThetaHalf(ixLab)+"^{\circ}")
xlim([ThetaHalf(1) ThetaHalf(end)])
xlabel('\theta_1_/_2');
ylabel('Coverage area m^2');
legend('With Beam','Without Beam','Manual')
grid on;
See Also
Categories
Find more on Line 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!