Remove White Space,Make Subplot Tight

版本 1.0.2 (2.9 KB) 作者: LittleTiger301
Make the most use of the matlab default figure set, adjust the position of the axes of subplot , remove white space,make figure tight.
71.0 次下载
更新时间 2022/10/5

查看许可证

Make the most use of the matlab default figure set, adjust the position of the axes of subplot , remove white space,make figure tight.
%***********************************************************************
function [] = MakeSubplotTight(Hgcf,Nrow,Ncol)
OR
function [] = MakeSubplotTight(Hgcf,Nrow,Ncol,MarginLeft,MarginRight,MarginTop,MarginBottom,GapRow,GapCol)
%Variables: At least 3 variables,and 6 optional variables,
% Hgcf (necessary) the handle of the figure
% Nrow (necessary) the number of the Rows of subplot( or plot )
% Ncol (necessary) the number of the Columns of subplot( or plot )
**********************Demo m. file*******************************
%----------------Create Some Data For Demon Test
X(1,:)=-1000000:100000:1000000;Y(1,:)=sin(X(1,:)./57.3);
X(2,:)=-1:0.1:1;Y(2,:)=cos(X(2,:)./57.3);
X(3,:)=-1:0.1:1;Y(3,:)=X(3,:).*X(3,:);
X(4,:)=-1:0.1:1;Y(4,:)=exp(X(4,:));
%----------------Figure Of Subplot :2 Rows× 2 Columns
Hgcf=figure('color','w'); %get the handle of the figure
Nrow=2;NCol=2;
subplot(Nrow,NCol,1);plot(X(1,:),Y(1,:),'r');xlabel('X1','fontsize',12);ylabel('Y1','fontsize',12);title('Figure1','fontsize',14);legend('Y1');
subplot(Nrow,NCol,2);plot(X(2,:),Y(2,:),'r');xlabel('X2','fontsize',12);ylabel('Y2','fontsize',12);title('Figure2','fontsize',14);legend('Y2');
subplot(Nrow,NCol,3);plot(X(3,:),Y(3,:),'r');xlabel('X3','fontsize',12);ylabel('Y3','fontsize',12);title('Figure3','fontsize',14);legend('Y3');
subplot(Nrow,NCol,4);plot(X(4,:),Y(4,:),'r');xlabel('X4','fontsize',12);ylabel('Y4','fontsize',12);title('Figure4','fontsize',14);legend('Y4');
%--------------Remobe White Space,Make Subplot Tight----------------------
MakeSubplotTight(Hgcf,Nrow,NCol); %the function needs at least 3 variables——the figure handle ,the number of the rows and columns of the subplot

引用格式

LittleTiger301 (2026). Remove White Space,Make Subplot Tight (https://ww2.mathworks.cn/matlabcentral/fileexchange/118560-remove-white-space-make-subplot-tight), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2010b
与 R2018a 及更高版本兼容
平台兼容性
Windows macOS Linux
致谢

参考作品: tightly_SubPlot

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.2

change title

1.0.1

Get rid of a few codes,make the function more effective。

1.0.0