Force tiledlayout('flow') to layout vertically

조회 수: 101 (최근 30일)
Scott
Scott 2020년 8월 16일
답변: Dave B 2023년 3월 17일
The problem I have with tiledlayout('flow') is that it it will often end up arranging the plots in a 2x2 grid, rather than a 4x1.
I understand tiledlayout('flow') tries to keep a 4:3 ratio for plots, but this is not useful for my data.
Tiledlayout(x,1) won't work because I don't know x beforehand.
I had hoped that in the case of tiledlayout(x,1) I could set the GridSize property, but it is read only.
Any suggestions on how to overcome this would be helpful, thank you.

채택된 답변

Dave B
Dave B 2023년 3월 17일
Starting in R2023a you can use the 'horizontal' and 'vertical' tile arrangements to accomplish layouts that are dynamically sized but only in one direction. More information available in the tiledlayout documentation.
figure(1)
t=tiledlayout('horizontal');
nexttile
plot(rand(1,10))
nexttile
bar(rand(1,10))
nexttile
scatter(rand(1,10),rand(1,10))
figure(2)
t=tiledlayout('vertical');
nexttile
plot(rand(1,10))
nexttile
bar(rand(1,10))
nexttile
scatter(rand(1,10),rand(1,10))

추가 답변 (1개)

Srivardhan Gadila
Srivardhan Gadila 2020년 8월 20일
Based on the above information and the documentation of tiledlayout & nexttile, for this particular problem you can make use of the 'nexttile(span)' syntax as follows:
% Let the max number tiles are maxTiles = 1000 (>>n or just >=n)
maxTiles = 1000;
x = linspace(0,30);
tiledlayout('flow')
n = randi([1 10]);
for i=1:n
nexttile([1 maxTiles])
y = rand(1,numel(x));
plot(x,y)
end
  댓글 수: 1
Scott
Scott 2020년 8월 20일
Thank you! That does work flawlessly indeed. I did read that documentation before, and I would not have thought to use it in this way.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by