1

在几个子图中,每个子图的 y 轴刻度具有不同的值。每个 ylabel 都有不同的对齐方式。有没有办法解决这个问题 - 将所有 ylabels 对齐到左边?

现在只能手动进行。

figure(1);
subplot 411; plot([1 2],[1 1000]);     ylabel 'Label 1';
subplot 412; plot([1 2],[1 1000]);     ylabel 'Label 2';
subplot 413; plot([1 2],[0.5 0.7]);    ylabel 'Label 3';
subplot 414; plot([1 2],[-5 0.0007]);  ylabel 'Label 4';

例子

我希望将所有 ylabel 对齐到左侧。

4

1 回答 1

1

如果您想自动对齐子图的 ylabel,则有一个File Exchange 脚本(您似乎从中获取了代码示例)。

通过您的示例,我发现我需要稍微更改代码。在文件align_Ylabels.m中,我必须从以下位置更改行118

tmp_max(k)  = size(yticks{k},2);

tmp_max(k)  = size(char(yticks{k}),2);

这可确保它实际上检查 yaxis 刻度线的字符长度。

运行您的示例,然后运行脚本:

figure(1);
subplot 411; plot([1 2],[1 1000]);     ylabel 'Label 1';
subplot 412; plot([1 2],[1 1000]);     ylabel 'Label 2';
subplot 413; plot([1 2],[0.5 0.7]);    ylabel 'Label 3';
subplot 414; plot([1 2],[-5 0.0007]);  ylabel 'Label 4';

align_Ylabels(gcf)

产生以下结果:
在此处输入图像描述

于 2019-01-28T17:49:00.483 回答