如何在tileedlayout图上添加跨度ylabel?

问题描述

我在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,'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'可以使代码更简洁,更快速。