Remove White Space,Make Subplot Tight

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 Downloads
Aktualisiert 5. Okt 2022

Lizenz anzeigen

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

Zitieren als

LittleTiger301 (2026). Remove White Space,Make Subplot Tight (https://de.mathworks.com/matlabcentral/fileexchange/118560-remove-white-space-make-subplot-tight), MATLAB Central File Exchange. Abgerufen.

Kompatibilität der MATLAB-Version
Erstellt mit R2010b
Kompatibel mit R2018a und späteren Versionen
Plattform-Kompatibilität
Windows macOS Linux
Quellenangaben

Inspiriert von: tightly_SubPlot

Community Treasure Hunt

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

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.2

change title

1.0.1

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

1.0.0