在左侧对齐子图ylabel

时间:2019-01-28 17:29:39

标签: matlab

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

现在只能手动操作。

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';

Example

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

1 个答案:

答案 0 :(得分:1)

如果您想自动对齐子图的ylabel,则有一个File Exchange script(您似乎是从此处获取代码示例的)。

在您的示例中,我发现我需要稍微更改代码。 在文件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)

产生以下结果:
enter image description here

相关问题