Why does the ylabel position differ although i use the same code for every figure?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lucas Junghans
le 20 Juil 2022
Commenté : dpb
le 20 Juil 2022
For 10 different figures i use the same code regarding the ylabel position nevertheless as you can see in the pictures my ylabel differ from each other. Can you please explain it to me, why this happens?
figure(1)
title("DC",FontSize=18)
hold on
plot(var1R1(1:15,1),"LineWidth",2)
plot(var1R2(1:15,1),"LineWidth",2)
plot(var1R3(1:15,1),"LineWidth",2)
plot(var1R4(1:15,1),"LineWidth",2)
hold off
legend("R1","R2","R3","R4","Fontsize",12,"Location","northwest")
xlabel("Widerstandswerte in 1/10 \Omega","FontSize",16)
ylh1 = ylabel("Amplitude relativ zur Grundschwingung in %","Fontsize",16);
ylh1.Position(1) = ylh1.Position(1) + abs(ylh1.Position(1)*0.2);
figure(10)
title("25.",FontSize=18)
hold on
plot(var1R1(136:150,1),"LineWidth",2)
plot(var1R2(136:150,1),"LineWidth",2)
plot(var1R3(136:150,1),"LineWidth",2)
plot(var1R4(136:150,1),"LineWidth",2)
hold off
legend("R1","R2","R3","R4","Fontsize",12,"Location","northwest")
xlabel("Widerstandswerte in 1/10 \Omega","FontSize",16)
ylh10 = ylabel("Amplitude relativ zur Grundschwingung in %","Fontsize",16);
ylh10.Position(1) = ylh10.Position(1) + abs(ylh10.Position(1)*0.2);
Hope you can help me.
Lucas:)
3 commentaires
dpb
le 20 Juil 2022
He's not saying use fixed labels but a fixed-width and consistent format field for the tickk labels -- the default format is %g which lets the number of digits and precision vary depending upon the values. Use a specifc %.2f or similar may minimize the differences in sizes (or may exacerbate, I don't know w/o trying) and so the spacing/location auto-selected for the label may be closer to the same.
Look at the position by default from the legends and see just what those differences are before you mess around with it -- the default position is computed in data units; alternatively, you could set to 'normalized' and use the same relative position overall. This will end up with the label in identical position on the figure, but different distance from the tck labels themselves.
It's not clear what effect you're trying to achieve and what difference it would make...
Réponse acceptée
Lucas Junghans
le 20 Juil 2022
Modifié(e) : Lucas Junghans
le 20 Juil 2022
1 commentaire
dpb
le 20 Juil 2022
That was my suggestion above -- although depending on the actual y tick values, the spacing may get close if the tick values have more digits. But the actual postion of the label will be constant.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!