Ploted graphs in tiled layout extends beyond figure
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi all, the problem I have is pretty self-explanatory. I am trying to used tiledlayout in order to produce 5 plots as shown by the code below.
The problem is however, that the last three plots are extending outside the figure boundary for some reason.
clear ; clc
x = linspace(0,30);
y = sin(x/2);
[X,Y,Z] = peaks(20);
t1 = tiledlayout(3, 1, 'TileSpacing', 'Compact') ;
t2 = tiledlayout(t1, 1, 2, 'TileSpacing', 'Compact') ;
t3 = tiledlayout(t1, 3, 1, 'TileSpacing', 'Compact') ;
t3.Layout.Tile = 2 ;
t3.Layout.TileSpan = [2 3] ;
% Plot top two figures
nexttile(t2)
contour(X, Y, Z)
nexttile(t2)
contour(X, Y, Z)
title(t2, 'Common Title')
xlabel(t2, 'Common xlabel')
ylabel(t2, 'Common ylabel')
% Plot bottom three figures
nexttile(t3)
plot(x, y)
nexttile(t3)
plot(x, y)
nexttile(t3)
plot(x, y)
title(t3, 'Common title')
xlabel(t3, 'Common xlabel')
ylabel(t3, 'Common ylabel')
The reason I am particularly keen on using tiledlayout is because of the common legends and titles functionality.
Thanks for your help in advance.
댓글 수: 0
채택된 답변
Adam Danz
2023년 2월 10일
The problem is that t1 has a layout of 3x1 but t3 which is nested in t1 is set to a span of 2x3.
t3.Layout.TileSpan = [2 3] ; % <----- problem
Change the span to [2,1]
x = linspace(0,30);
y = sin(x/2);
[X,Y,Z] = peaks(20);
t1 = tiledlayout(3, 1, 'TileSpacing', 'Compact') ;
t2 = tiledlayout(t1, 1, 2, 'TileSpacing', 'Compact') ;
t3 = tiledlayout(t1, 3, 1, 'TileSpacing', 'Compact') ;
t3.Layout.Tile = 2 ;
t3.Layout.TileSpan = [2 1] ;
% Plot top two figures
nexttile(t2)
contour(X, Y, Z)
nexttile(t2)
contour(X, Y, Z)
title(t2, 'Common Title')
xlabel(t2, 'Common xlabel')
ylabel(t2, 'Common ylabel')
% Plot bottom three figures
nexttile(t3)
plot(x, y)
nexttile(t3)
plot(x, y)
nexttile(t3)
plot(x, y)
title(t3, 'Common title')
xlabel(t3, 'Common xlabel')
ylabel(t3, 'Common ylabel')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axes Appearance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!