Why does the ylabel position differ although i use the same code for every figure?

1 view (last 30 days)
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
Lucas Junghans
Lucas Junghans on 20 Jul 2022
hm..firstly thanks for your answer and your ideas. However im not sure, if using fixed y tick labels is a good idea for my needs, because as you can see the values differ a lot from each other (1.2% or 40%).
I will try to adjust it manually via Property Manager.
dpb
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...

Sign in to comment.

Accepted Answer

Lucas Junghans
Lucas Junghans on 20 Jul 2022
Edited: Lucas Junghans on 20 Jul 2022
I've figured it out and answer it for other people facing the same issue.
What worked for me was opening the figure --> property Manager --> select your label you want to move by clicking on it while the property manager is open --> Submenu Positions --> Units = normalized --> Positions = -0.05; 0.5; 0 (in my case)
Now my alignment is the same no matter the ticks on my ylabel.
Once you know what properties you want to change you can to this also via code.
Hope i can help someone else as well:)
  1 Comment
dpb
dpb on 20 Jul 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.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!