How can I adjust the space between each subplot for a 5*3 subplots setup?

I know I need to have a format like this below but I could not figure out what are the values should be in after the 'position' parameter.
Also, I want to keep the title for each subplot.
ESPECIALLY, I don't want the vertical distance between each column of the subplot so large. It seems the distance between each column of the subplot becomes larger as the number of rows of subplots get larger.
Also its ok that if I can edit and change the space after I saved the figure as a .fig file. But not sure how.
Thank you for your hints/helps in advance.
subplot(5,3,1);imshow(a1_1,[]);title('(a1)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,2);imshow(a2_1,[]);title('(a2)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,3);imshow(a3_1,[]);title('(a3)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,4);imshow(b1_1,[]);title('(b1)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,5);imshow(b2_1,[]);title('(b2)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,6);imshow(b3_1,[]);title('(b3)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,7);imshow(c1_1,[]);title('(c1)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,8);imshow(c2_1,[]);title('(c2)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,9);imshow(c3_1,[]);title('(c3)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,10);imshow(d1_1,[]);title('(d1)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,11);imshow(d2_1,[]);title('(d2)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,12);imshow(d3_1,[]);title('(d3)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,13);imshow(e1_1,[]);title('(e1)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,14);imshow(e2_1,[]);title('(e2)');set(gca,'xtick',[],'ytick',[])
subplot(5,3,15);imshow(e3_1,[]);title('(e3)');set(gca,'xtick',[],'ytick',[])
ha=get(gcf,'children');
set(ha(1),'position',[ ])
set(ha(2),'position',[ ])
set(ha(3),'position',[ ])
set(ha(4),'position',[ ])
set(ha(5),'position',[ ])
set(ha(6),'position',[ ])
set(ha(7),'position',[ ])
set(ha(8),'position',[ ])
set(ha(9),'position',[ ])
set(ha(10),'position',[ ])
set(ha(11),'position',[ ])
set(ha(12),'position',[ ])
set(ha(13),'position',[ ])
set(ha(14),'position',[ ])
set(ha(15),'position',[ ])

5 Comments

If you want to adjust spacing arbitrarily, then tiledlayout will be a better option than subplot. See - Name-Value Argumens for tiledlayout
If you want to adjust spacing with a particular spacing distance in mind, you will have to get the existing positions of subplots and modify accordingly.
Thanks, how to get existing positions of subplots and modify them? I think I need a specific
Especially, I don't want the vertical distance between each column of the subplot so large. It seems the distance between each column of the subplot becomes larger as the number of rows of subplots get larger.
Did you check out the links I and @Matt J mentioned?
I'm not sure how to adjust the vertical space among the subplots, as I said, the distance between each column of the subplot becomes larger as the number of rows of subplots get larger. Even I use TileSpacing = 'tight', there are still big vertical spaces among subplots (when I have 3 columns). For exmaple:

Sign in to comment.

Answers (2)

The subaxis function in this FEX download
offers specific settings for horizontal and vertical spacing.
n=4;
figure;
for i=1:n
subaxis(1,n,i, 'SpacingHoriz',0);
imagesc(phantom(128)); axis image off
colormap(gray)
end
figure;
for i=1:n
subaxis(1,n,i, 'SpacingHoriz',0.05);
imagesc(phantom(128)); axis image off
colormap(gray)
end
n=4;
%1x4
figure;
t=tiledlayout(1,n,'TileSpacing','tight');
for i=1:prod(t.GridSize)
nexttile
imagesc(phantom(128)); axis image off
colormap(gray)
end
%3x4
figure;
t=tiledlayout(3,n,'TileSpacing','tight');
for i=1:prod(t.GridSize)
nexttile
imagesc(phantom(128)); axis image off
colormap(gray)
end

1 Comment

As I said, the distance between each column of the subplot becomes larger as the number of rows of subplots get larger.
It's because the tiledlayout expands elastically to fill the figure window. If you narrow the window, you should see the thumbnails compress together.

Sign in to comment.

Tags

Asked:

on 14 Oct 2023

Moved:

on 15 Oct 2023

Community Treasure Hunt

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

Start Hunting!