如何消除子图和周围的差距

use*_*419 10 matlab margins subplot

我在一个图中绘制了两个子图(2x1).我想删除两个子图之间的所有间距,并删除顶部子图的xlable和xlabel刻度.此外,我试图删除子图外的所有间距.我试试

set(gca, 'LooseInset', get(gca,'TightInset'))
Run Code Online (Sandbox Code Playgroud)

但它不起作用.现在我手动删除这些边距和标签,我需要处理60个数字并且手动执行所有这些操作非常耗时.有更好的方法吗?谢谢.

我也尝试了subtightplot,它有助于减少所有边距,但xlabel和ylabel也被剪切

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);
Run Code Online (Sandbox Code Playgroud)

我也尝试了subplot_tight,但情况更糟

bla*_*bla 7

您可以使用FEX中的subplot_tightsubtightplot.删除所有x-tick和标签使用:

set(gca, 'XTickLabel', [],'XTick',[])
Run Code Online (Sandbox Code Playgroud)

在适当的子情节......

编辑:

由于您确实想要包含标签等,因此您可以使用以下position句柄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);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述