In Matlab, if we do not rotate the y-label that contains several letters, the label may overlap with the tick numbers or even the y-axis. We can increase the distance between the y-label and the y-axis in the following way:
plot(A, B);
y=ylabel('xxx', 'rot', 0); % do not rotate the y label
set(y, 'position', get(y,'position')-[0.1,0,0]); % shift the y label to the left by 0.1
However, a problem is that if we change axis([0 1 0 25])
to axis([0 10 0 25])
, the distance between the y-label and the y-axis will also change. Is there a convenient way to shift the y-label slightly to the left, but keep the distance between the y-label and the y-axis constant when we change the range of x?
You can use normalized units for the y-label position. Try this:
set(y, 'Units', 'Normalized', 'Position', [-0.1, 0.5, 0]);
Normalized units are always relative to [0 1], so the range of your data doesn't matter.