How to adjust the position of the x-axis ticks and put the angle degree on the values of the x-axis ticks?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Haitham AL Satai
el 4 de Oct. de 2022
Comentada: Haitham AL Satai
el 5 de Oct. de 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 comentarios
Respuesta aceptada
Les Beckham
el 4 de Oct. de 2022
Editada: Les Beckham
el 4 de Oct. de 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 comentarios
Más respuestas (1)
dpb
el 4 de Oct. de 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;
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!