How to generate unaligned subplots using tiledlayout?
조회 수: 5 (최근 30일)
이전 댓글 표시
I plan to generate a plot that has 3 subplots on the first row, 4 subplots on the second row using tiledlayout. As 4 is not a multiple of 3, I have difficulties to correctly manage it. All examples I have seen are aligned subplots (tiles) though.
Normally I will do that with something like:
subplot(2,3,1); plot(...);
subplot(2,3,2); plot(...);
subplot(2,3,3); plot(...);
subplot(2,4,5); plot(...);
subplot(2,4,6); plot(...);
subplot(2,4,7); plot(...);
Is it possible to achieve this goal by using tiledlayout?
댓글 수: 0
채택된 답변
Dave B
2021년 10월 28일
편집: Dave B
2021년 10월 28일
tiledlayout requires that your grid is fixed, but you can do this in two ways:
First approach: least common multiple with tilespan. This gives you simple looking code but you'll have to think about the math a bit.
figure(1)
tiledlayout(2,12)
nexttile([1 4])
nexttile([1 4])
nexttile([1 4])
nexttile([1 3])
nexttile([1 3])
nexttile([1 3])
Second approach: nested layouts. I like this because it's easy for me to picture a layout with multiple sub-layouts, but it means thinking about the graphics tree a bit when you add new things.
figure(2)
tcl_parent = tiledlayout(2,1);
tcl_top = tiledlayout(tcl_parent,1,3);
nexttile(tcl_top)
nexttile(tcl_top)
nexttile(tcl_top)
tcl_bot = tiledlayout(tcl_parent,1,4);
% note that while nexttile lets you specify a tile, when you parent
% a layout to another layout you have to manually specify the tile
tcl_bot.Layout.Tile = 2;
nexttile(tcl_bot)
nexttile(tcl_bot)
nexttile(tcl_bot)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!