如何在Matlab中调整y-label与y轴的距离?

时间:2022-12-09 20:16:09

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:

共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识共识我们可以通过以下方式增加y-label和y轴之间的距离:

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?

然而,问题是如果我们改变轴([0 10 25])到轴([0 10 0 25]),y-标与y轴之间的距离也会改变。是否有一种方便的方法将y标签稍微移到左边,但是当我们改变x的范围时,保持y轴与y轴之间的距离?

1 个解决方案

#1


17  

You can use normalized units for the y-label position. Try this:

你可以使用标准化单位的y标签位置。试试这个:

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.

归一化的单位总是相对于[0 1],所以你的数据的范围并不重要。

#1


17  

You can use normalized units for the y-label position. Try this:

你可以使用标准化单位的y标签位置。试试这个:

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.

归一化的单位总是相对于[0 1],所以你的数据的范围并不重要。