How to adjust the position of the x-axis ticks and put the angle degree on the values of the x-axis ticks?

4 ビュー (過去 30 日間)
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;

採用された回答

Les Beckham
Les Beckham 2022 年 10 月 4 日
編集済み: Les Beckham 2022 年 10 月 4 日
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

その他の回答 (1 件)

dpb
dpb 2022 年 10 月 4 日
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)];
ans = 1×9
5 10 15 20 25 30 40 50 60
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;

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by