MATLAB: Different rows height in tiled layout

plottiledchartlayouttiledlayouttilled-layout

Hello,
is it possible to adjust row height in tilled layout? I have six plots in tiled layout (2×3). Each of them has own legend. In first and second plot there is 6 items, but in next plots there is only one item to display in legend.
The problem is that all tiles has the same size so there is large space between second and last row. Is it possible to change it?
X = 0:0.01:2*pi;
Y = sin(X);
tiledlayout(3, 2)
nexttile
hold on
plot(X, Y, "DisplayName",'A1')
plot(X, Y, "DisplayName",'A2')
plot(X, Y, "DisplayName",'A3')
plot(X, Y, "DisplayName",'A4')
plot(X, Y, "DisplayName",'A5')
plot(X, Y, "DisplayName",'A6')
legend
nexttile
hold on
plot(X, Y, "DisplayName",'A1')
plot(X, Y, "DisplayName",'A2')
plot(X, Y, "DisplayName",'A3')
plot(X, Y, "DisplayName",'A4')
plot(X, Y, "DisplayName",'A5')
plot(X, Y, "DisplayName",'A6')
legend
nexttile
hold on
plot(X, Y, "DisplayName",'A1')
legend
nexttile
hold on
plot(X, Y, "DisplayName",'A1')
legend
nexttile
hold on
plot(X, Y, "DisplayName",'A1')
plot(X, Y, "DisplayName",'A2')
plot(X, Y, "DisplayName",'A3')
plot(X, Y, "DisplayName",'A4')
legend
nexttile
hold on
plot(X, Y, "DisplayName",'A1')
plot(X, Y, "DisplayName",'A2')
plot(X, Y, "DisplayName",'A3')
plot(X, Y, "DisplayName",'A4')
legend

Best Answer

Another solution would be to use nested tiledlayouts, e.g.,
m1=[5,6];
m2=[1,1,1,2];
T=tiledlayout(5,1); %Outer layout
t=tiledlayout(T,1,2); %first inner layout
t.Layout.Tile=1;
t.Layout.TileSpan=[2,1];
for i=1:2
nexttile(t);
plot(rand(5,m1(i)));
legend('Location','southoutside')
end
t=tiledlayout(T,2,2); %second inner layout
t.Layout.Tile=3;
t.Layout.TileSpan=[3,1];
for i=1:4
nexttile(t);
plot(rand(5,m2(i)));
legend('Location','southoutside')
end
Related Question