tiledlayout no spacing display in 2x3 grid

48 ビュー (過去 30 日間)
Rupesh Gupta
Rupesh Gupta 2022 年 7 月 20 日
コメント済み: Adam Danz 2022 年 7 月 20 日
How to plot tiledlayout 2x3 grid without any spacing between plots? I'm using these commands
t = tiledlayout(2,3);
t.TileSpacing = 'none';
but still have spacing between the columns.
  2 件のコメント
Voss
Voss 2022 年 7 月 20 日
It seems to do the right thing in this case:
t = tiledlayout(2,3);
t.TileSpacing = 'none';
for ii = 1:6
nexttile(t)
plot(1:10)
end
Maybe something in your plotting code is changing the spacing. Can you share the rest of your code?
Rupesh Gupta
Rupesh Gupta 2022 年 7 月 20 日
fh=figure;
fh.WindowState = 'maximized';
t = tiledlayout(2,3);
t.TileSpacing = 'none';
nexttile
% read img
imshow(img)
for idx = 1:5
nexttile
% read img
imshow(img)
end
This is essentially what I'm running, I'm wondering if I have to adjust the aspect ratio.

サインインしてコメントする。

回答 (2 件)

Adam Danz
Adam Danz 2022 年 7 月 20 日
編集済み: Adam Danz 2022 年 7 月 20 日
imshow fits the axes to your image size.
Use axis normal if you don't want the axes to tighten. This will distort your image if you expect it to have a uniform aspect ratio.
Example showing default behavior (axis on to see borders)
figure
tiledlayout(2,2,'TileSpacing','None');
for i = 1:4
nexttile
imshow(rand(700,300))
axis on
end
Example after applying axis normal (axis on to see borders)
figure
tiledlayout(2,2,'TileSpacing','None');
for i = 1:4
nexttile
imshow(rand(700,300))
axis normal
axis on
end

Voss
Voss 2022 年 7 月 20 日
imshow effectively sets the aspect ratio so that the image doesn't look distorted.
If you want to have no space between the tiles, at the expense of potentially distorting the images, one way to do that would be to use the low-level image function instead of imshow:
% some random image data
image_data = cell(2,3);
for ii = 1:6
image_data{ii} = randi([0 255],20,8,3,'uint8');
end
% first, using imshow, for reference
figure
t = tiledlayout(2,3);
t.TileSpacing = 'none';
for ii = 1:6
nexttile(t)
imshow(image_data{ii})
end
% now, using image. images are stretched, but there's no space between them
figure
t = tiledlayout(2,3);
t.TileSpacing = 'none';
for ii = 1:6
nexttile(t)
image(image_data{ii})
end
  2 件のコメント
Rupesh Gupta
Rupesh Gupta 2022 年 7 月 20 日
Both suggestions above makes sense, but I would like to keep the aspect ratio of the image, so I guess I would have to accept some column spacing.
Thanks for the help though.
Adam Danz
Adam Danz 2022 年 7 月 20 日
Not sure what the end goal is but maybe imtile would come in handy.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by