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
Dyuman Joshi
2023년 10월 14일
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.
Chen
2023년 10월 14일
Dyuman Joshi
2023년 10월 15일
답변 (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
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.
카테고리
도움말 센터 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




