how to remove the gap between subplots and around [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-18 12:36:30

问题


I am plotting two subplots (2x1) in one figure. I would like to remove all the spacing between two subplots and remove the xlable and xlabel ticks for the top subplot too. Also, I am trying to remove all the spacing outside the subplot. I try

set(gca, 'LooseInset', get(gca,'TightInset'))

But it doesn't work. Now I am removing those margins and labels manually, I have 60 figures need to be handled and doing all those manually is time consuming. Any better way to do it? Thanks.

I also try the subtightplot, it helps to reduce all the margins but the xlabel and ylabel are also cut

margins=[0 0];
t = 0:0.01:10;
y1 = sin(t);
y2 = cos(t);
h1 = subtightplot(2,1,1, margins);
plot(t, y1);
ystr = {'sin(x)','(dimensionless)'}
hy1 = ylabel(ystr);
set(gca, 'fontsize', 14);
set(hy1, 'fontsize', 14);
set(gca, 'XTickLabel', [],'XTick',[])

h2 = subtightplot(2,1,2,margins);
plot(t, y2, 'r-o');
hx2=xlabel('frequency');
hy2=ylabel('amplitude');
set(gca, 'fontsize', 14);
set(hx2, 'fontsize', 14);
set(hy2, 'fontsize', 14);

I also try the subplot_tight but it is even worse


回答1:


you can use subplot_tight or subtightplot from the FEX. to remove all x-tick and labels use:

set(gca, 'XTickLabel', [],'XTick',[])

in the appropriate subplot...

Edit:

Since you do want to include the labels etc, you can so it using the position handle in axes:

t = 0:0.01:10;
y1 = sin(t);
y2 = cos(t);


left= 0.15;
bottom1=0.5;
bottom2=0.05;
width=0.8;
height=0.45; % which is also bottom1-bottom2

axes('Position',[left bottom1 width height]);
plot(t, y1);
ystr = {'sin(x)','(dimensionless)'}
hy1 = ylabel(ystr);
set(gca, 'fontsize', 14);
set(hy1, 'fontsize', 14);
set(gca, 'XTickLabel', [],'XTick',[])


axes('Position',[left bottom2 width height])
plot(t, y2, 'r-o');
hx2=xlabel('frequency');
hy2=ylabel('amplitude');
set(gca, 'fontsize', 14);
set(hx2, 'fontsize', 14);
set(hy2, 'fontsize', 14);



来源:https://stackoverflow.com/questions/16409343/how-to-remove-the-gap-between-subplots-and-around

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!