Why does the ylabel position differ although i use the same code for every figure?
Show older comments
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 Comments
Jonas
on 20 Jul 2022
i gues the issue are the numbers on the yaxis (the y tick labels). you can try to set a fixed ytickformat with fixed field width or you can try plotting into a tiledlayout
Lucas Junghans
on 20 Jul 2022
dpb
on 20 Jul 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...
Accepted Answer
More Answers (0)
Categories
Find more on Axis Labels 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!