필터 지우기
필터 지우기

Ploted graphs in tiled layout extends beyond figure

조회 수: 4 (최근 30일)
KostasK
KostasK 2023년 2월 10일
댓글: KostasK 2023년 2월 10일
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.

채택된 답변

Adam Danz
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 CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by