如何在 tiledlayout 图上添加跨越 ylabel?

How to add a spanning ylabel on tiledlayout plots?

我在 MATLAB 中有一个包含 3 个图块的图块布局,我想在 y 轴左侧添加一个垂直标签,跨越所有图块。

figure('units','normalized','outerposition',[0 0 0.4 0.91])
tlo = tiledlayout(3,1,'TileSpacing','none','Padding','none');
nexttile
set(gca,'XColor','none')
hold on
plot(x1)
hold off
nexttile
set(gca,'XColor','none')
hold on
plot(x2)
hold off
nexttile
hold on
plot(x3)
hold off

正如 documentation on tiledlayout() 告诉你的:

title(t,'Size vs. Distance')
xlabel(t,'Distance (mm)')
ylabel(t,'Size (mm)')

生成跨越轴标签和标题。你的情况 ylabel(tlo,'Your Y label');


两个样式注释:

  • 如果您只绘制一个图,则无需 hold on;hold off 每个图。另外 hold off 仅在您不想再保留情节时才需要,即当您想要覆盖其内容时。

  • set(gca, __) 已被 OOP 样式语法取代。使用 t1 = nexttile; t1.XColor = 'none' 可以使代码更清晰、速度更快。