Ploted graphs in tiled layout extends beyond figure

3 Ansichten (letzte 30 Tage)
KostasK
KostasK am 10 Feb. 2023
Kommentiert: KostasK am 10 Feb. 2023
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.

Akzeptierte Antwort

Adam Danz
Adam Danz am 10 Feb. 2023
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')

Weitere Antworten (0)

Kategorien

Mehr zu Axes Appearance finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by