且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何消除子图之间的差距

更新时间:2023-11-21 16:44:34

您可以使用 subplot_tight subtighttlot . 删除所有x-tick和标签,请使用:

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...

由于您确实希望包含标签等,因此可以使用axes中的position手柄进行处理:

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);