I'm currently trying to create a script that can automatically format all of my plots for me. I'm encountering a weird issue in trying to set the font size for the XLabel and YLabel.
To demonstrate this problem.
s = tf('s');
H = 1/(s+1);
step(H);
h = xlabel("Time", "FontSize", 20);
h =
Text (time (seconds)) with properties:
String: 'Time'
FontSize: 20
FontWeight: 'normal'
FontName: 'Helvetica'
Color: [0 0 0]
HorizontalAlignment: 'center'
Position: [223 -20.6667 0]
Units: 'pixels'
So far, everything works and we can print out h and see that it has the correct font size.
However, if we look at the font size property using gca, it doesn't work.
ax = gca;
ax.XLabel
ans =
Text with properties:
String: ''
FontSize: 11
FontWeight: 'normal'
FontName: 'Helvetica'
Color: [0.4000 0.4000 0.4000]
HorizontalAlignment: 'center'
Position: [4.5000 -0.0744 -10]
Units: 'data'
Then, if we use gca to set the XLabel, another label pops up. It seems like there are two separate XLabel properties within the plot.
ax.XLabel.String = "hello";
I tried to replicate this problem with plot(), but that function works fine. Maybe this is unique to step(). I haven't tested with other plotting functions. Any advice on what to do if I want to automate formatting all my plots using gca?
3 Comments
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/651138-xlabel-and-ylabel-font-size#comment_1140803
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/651138-xlabel-and-ylabel-font-size#comment_1140803
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/651138-xlabel-and-ylabel-font-size#comment_1140848
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/651138-xlabel-and-ylabel-font-size#comment_1140848
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/651138-xlabel-and-ylabel-font-size#comment_1141088
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/651138-xlabel-and-ylabel-font-size#comment_1141088
Sign in to comment.