フィルターのクリア

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 Center および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by