在 matlab 中更改刻度标签和轴之间的 space(刻度标签和 ylabel 或 xlabel 相同)

Change the space between the ticklabels and axes (same for ticklabel and ylabel or xlabel) in matlab

如何在 ticklabels 和轴 (s2) 之间更改 space,对于 matlab 中的 ticklabel 和 ylabel 或 xlabel (s1, s3) 也是如此(我使用的是 matlab 2015b)。

如果您在 xlabel and ylabel you will see that you can specify the optional output argument to return a Text object, which you can use to access and modify the properties of the label 创建后阅读文档。

这里感兴趣的是标签的 'Position' 属性,它是一个 [x y z*] 位置向量(z 是可选的)。例如:

plot(1:10);
xl = xlabel('An X Label');
yl = ylabel('A Y Label');

生成以下内容:

然后我们可以调整:

xl.Position(2) = 0.15;  % Shift x label down
yl.Position(1) = 0.20;  % Shift y label left

据我所知,我不相信有一种简单的方法可以调整刻度偏移量。

对于坐标轴标签,. For the axis tick labels you can use text 以您想要的偏移量创建新的刻度标签:

x = 1:10;
y = 2*x;
plot(x,y)
ax = gca;
S2 = 2; % this is S2 from your qusetion, in your data units
% make a vector of vertical position after the offset:
offset = repmat(ax.YTick(1)-S2,1,numel(ax.XTick));
% create new lables:
text(ax.XTick,offset,ax.XTickLabel,'HorizontalAlign','center')
% remove the original ones:
ax.XTickLabel = [];

结果: