在几个子图中,每个子图中的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';
我希望将所有ylabel对齐到左侧。
答案 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)