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

198 Ansichten (letzte 30 Tage)
Chen
Chen am 14 Okt. 2023
Verschoben: Matt J am 15 Okt. 2023
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 Kommentare
Chen
Chen am 15 Okt. 2023
Bearbeitet: Chen am 15 Okt. 2023
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:

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Matt J
Matt J am 15 Okt. 2023
Bearbeitet: Matt J am 15 Okt. 2023
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

Matt J
Matt J am 15 Okt. 2023
Bearbeitet: Matt J am 15 Okt. 2023
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 Kommentar
Matt J
Matt J am 15 Okt. 2023
Verschoben: Matt J am 15 Okt. 2023
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.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by