You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用tiledlayout绘制第一行3个、第二行4个的非对齐子图?

可以实现,你可以通过设置更大的基础网格,搭配子图跨列的方式完成这种非对齐布局,具体实现思路和示例如下:

我们需要先取两行各自子图数量的最小公倍数作为基础网格的总列数,你要第一行3张、第二行4张,二者的最小公倍数是12,因此我们初始化一个2行×12列的tiledlayout网格,让第一行每张子图跨4列(12÷3=4),第二行每张子图跨3列(12÷4=3),刚好可以填满整行,且上下行子图不对齐。

% 初始化2行12列的瓷砖布局
t = tiledlayout(2,12);
% 可选:调整布局间距
t.Padding = 'compact';
t.TileSpacing = 'compact';

% 第一行3张子图,每张跨4列
nexttile(1, [1 4])
plot(1:10) % 替换为你的绘图逻辑
title('子图1')

nexttile(5, [1 4])
plot(1:10)
title('子图2')

nexttile(9, [1 4])
plot(1:10)
title('子图3')

% 第二行4张子图,每张跨3列
nexttile(13, [1 3])
plot(1:10)
title('子图4')

nexttile(16, [1 3])
plot(1:10)
title('子图5')

nexttile(19, [1 3])
plot(1:10)
title('子图6')

nexttile(22, [1 3])
plot(1:10)
title('子图7')

如果后续需要更复杂的非对齐布局,都可以用同样的逻辑,先计算最小公倍数设置基础网格,再通过nexttile的跨度参数自定义每个子图的占用范围,比混用不同网格参数的subplot写法更稳定,不会出现子图覆盖的问题。

内容的提问来源于stack exchange,提问作者livemyaerodream

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 02:45:02