tiledlayout doesn't behave as it should
46 ビュー (過去 30 日間)
古いコメントを表示
Followed the example of https://www.mathworks.com/help/matlab/ref/tiledlayout.html with 'TileSpacing', 'none'option. The output is as image shown with huge gap in rows.
row = 8;
col = 5;
figure
tiledlayout(row,col,'TileSpacing','none');
for ns = 1:nums
nexttile
imagesc(images(:,:,ns));colormap gray;axis off; axis square
end

2 件のコメント
Simon Chan
2025 年 1 月 19 日 2:33
Because you use "axis square" which forces each image to be a square. However, if you check each axis positions, I believe they are touching each other, since Tilespacing is set to "none".
回答 (2 件)
Madheswaran
2025 年 1 月 21 日 6:13
Hello,
When a figure is created in MATLAB, it automatically assigns default position values based on your screen size. If these position values do not align well with the axes inside the figure, it can result in gaps between the tiles.
To eliminate these gaps, one option is to set the axis to 'normal', allowing each axis to be flexible. I've generated some images using random data, and here's an example of how the final figure would appear:

However if you prefer each tile to maintain a square shape, you can adjust the figure size using the Position property as shown below:
set(gcf, 'Position', [534.6000 73.0000 404.4000 615.2000]); % Adjust these values as per your requirement

Hope this helps!
0 件のコメント
Vinay
2025 年 1 月 21 日 7:04
Hi @John
The `tiledlayout` function assigns a fixed tile to each subplot. When the `TileSpacing` property is set to `'none'`, it removes the spacing between tiles. However, enabling the `'axis square'` option enforces a 1:1 aspect ratio for each plot, ensuring that the height and width of each axis box are equal.
I have created 4 different plots using random data where 'sample4' axis is set as square which causes shrinking along the horizontal axis to maintain 1:1 aspect ratio causing the spacing between the tiles as shown in the below figure

'axis equal' can be used to keep the axis width and height same with equal spacing on both axes.This ensures zero spacing between the tiles as shown below

Additionally we can set the figure with a square aspect ratio to minimize the spacing.
figure('Position', [100, 100, 600, 600]);
I hope this resolves the query!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!