【问题标题】:Align subplots ylabel's in left side在左侧对齐子图 ylabel
【发布时间】:2019-01-28 17:29:38
【问题描述】:

在几个子图中,每个子图的 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';

Example

我希望所有的 ylabel 都向左对齐。

【问题讨论】:

    标签: matlab


    【解决方案1】:

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

    通过您的示例,我发现我需要稍微更改代码。 在文件align_Ylabels.m 中,我不得不将118 行从:

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

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

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

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

    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)
    

    产生以下结果:

    【讨论】:

    • 太棒了。我已经尝试过该代码,但并不好。现在,按照建议更改第 118 行,结果完全符合我的需要。谢谢。
    • 这就是为什么重要的是始终包括您自己尝试过的所有步骤。如果您表明您已经尝试过此脚本,我将能够更轻松地找到问题。
    猜你喜欢
    • 2012-05-24
    • 2016-01-04
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 2017-05-25
    相关资源
    最近更新 更多