# How to reduce space between plots in subplot and how to increase the area of plot in subplot

9 views (last 30 days)
Commented: Matt J on 27 Apr 2021
I have the created the following vector plots by using subplot but, there are larger wider space in between plots in horizontal direction and the area of plots is also less. Kindly help me with the problem. please fid below the code for the plotted vetor field
clear all;close all;clc
format long
fid=fopen('50112.txt');
fulltext=textscan(fid,'%s','delimiter','\n');
numberofgridpoints=length(fulltext{1});
fclose(fid);
n=numberofgridpoints/200;
fid=fopen('50112.txt');
datamatrix=fscanf(fid,'%f%f%f%f',[4,inf]);
%-------stroing of velocity data -----------%
for i=1:200
c=i-1;
for j=1:n
d=(c*n)+j;
x(j)=datamatrix(1,j);
y(j)=datamatrix(2,j);
u(i,j)=datamatrix(3,d);
v(i,j)=datamatrix(4,d);
end
end
%*********************************************%
%-------Proper Orthogonal Decompostion--------%
%*********************************************%
%---Calcalating the covarience matrix---------%
c1=u*u';
c2=v*v';
c=(c1+c2)/200;
[beta, lmd]=svd(c);
phix=u'*beta;
phiy=v'*beta;
for j=1:200
phinor=0;
for i=1:n
phinor=phinor+phix(i,j)^2+phiy(i,j)^2;
end
phinor=sqrt(phinor);
phix(:,j)=phix(:,j)/phinor;
phiy(:,j)=phiy(:,j)/phinor;
end
timecoeu=u*phix;
timecoev=v*phiy;
timecoe=timecoeu+timecoev;
%---------velocity recosntruction------------%
for i=1:n
for j=200
meanu(i,j)=0;
coherentu(i,j)=0;
transitionu(i,j)=0;
turbulentu(i,j)=0;
meanv(i,j)=0;
coherentv(i,j)=0;
transitionv(i,j)=0;
turbulentv(i,j)=0;
tvmean(i,j)=0;
tvcoherentv(i,j)=0;
tvtransition(i,j)=0;
tvturbulent(i,j)=0;
end
end
for i=1:200
for j=1:1
meanu(:,i)=timecoe(i,j)*phix(:,j)+meanu(:,i);
meanv(:,i)=timecoe(i,j)*phiy(:,j)+meanv(:,i);
end
end
for i=1:200
for j=2:9
coherentu(:,i)=timecoe(i,j)*phix(:,j)+coherentu(:,i);
coherentv(:,i)=timecoe(i,j)*phiy(:,j)+coherentv(:,i);
end
end
for i=1:200
for j=10:186
transitionu(:,i)=timecoe(i,j)*phix(:,j)+ transitionu(:,i);
transitionv(:,i)=timecoe(i,j)*phiy(:,j)+ transitionv(:,i);
end
end
for i=1:200
for j=187:200
turbulentu(:,i)=timecoe(i,j)*phix(:,j)+ turbulentu(:,i);
turbulentv(:,i)=timecoe(i,j)*phiy(:,j)+ turbulentv(:,i);
end
end
%-----------CYCLE 1------------%
subplot(4,2,1)
tvmean(:,1)=sqrt(meanu(:,1).^2+meanv(:,1).^2);
tvmeanpart=reshape(tvmean(:,1),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvmeanpart,100,'linestyle','none')
hold on
quiver(x,y,meanu(:,1).',meanv(:,1).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('mean part (#1)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,3)
tvcoherent(:,1)=sqrt(coherentu(:,1).^2+coherentv(:,1).^2);
tvcoherentpart=reshape(tvcoherent(:,1),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvcoherentpart,100,'linestyle','none')
hold on
quiver(x,y,coherentu(:,1).',coherentv(:,1).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('coherent part (#1)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,5)
tvtransition(:,5)=sqrt(transitionu(:,5).^2+transitionv(:,5).^2);
tvtransitionpart=reshape(tvtransition(:,5),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvtransitionpart,100,'linestyle','none')
hold on
quiver(x,y,transitionu(:,5).',transitionv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('transition part (#1)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,7)
tvturbulent=sqrt(turbulentu(:,1).^2+turbulentv(:,1).^2);
tvturbulentpart=reshape(tvturbulent,[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvturbulentpart,100,'linestyle','none')
hold on
quiver(x,y,turbulentu(:,1).',turbulentv(:,1).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('turbulent part (#1)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
%----------END of CYCLE 1-------%
%-----------CYCLE 5------------%
subplot(4,2,2)
tvmean(:,5)=sqrt(meanu(:,5).^2+meanv(:,5).^2);
tvmeanpart=reshape(tvmean(:,5),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvmeanpart,100,'linestyle','none')
hold on
quiver(x,y,meanu(:,5).',meanv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('mean part (#5)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,4)
tvcoherent(:,5)=sqrt(coherentu(:,5).^2+coherentv(:,5).^2);
tvcoherentpart=reshape(tvcoherent(:,5),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvcoherentpart,100,'linestyle','none')
hold on
quiver(x,y,coherentu(:,5).',coherentv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('coherent part (#5)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,6)
tvtransition(:,5)=sqrt(transitionu(:,5).^2+transitionv(:,5).^2);
tvtransitionpart=reshape(tvtransition(:,5),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvtransitionpart,100,'linestyle','none')
hold on
quiver(x,y,transitionu(:,5).',transitionv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('transition part (#5)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,8)
tvturbulent=sqrt(turbulentu(:,5).^2+turbulentv(:,5).^2);
tvturbulentpart=reshape(tvturbulent,[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvturbulentpart,100,'linestyle','none')
hold on
quiver(x,y,turbulentu(:,5).',turbulentv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('turbulent part (#5)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
%----------END of CYCLE 5-------%
DGM on 26 Apr 2021
I resized the figure window by clicking on the corner and dragging it.

the cyclist on 23 Apr 2021
Edited: Adam Danz on 26 Apr 2021
This might require an overhaul of your code, but I would say you can probably achieve better results with the new(er) tiledlayout method of creating subplots.
@Adam Danz Thank you for your kindful information but the plot is required to be in same way as i have mentioned in the questioning section, it is required to show x axis and colobar to all plots in the figure but it is also required to remove the aweful sapcing in horizontal direction. Kindly find my code below and data file for reference.
%--------------------------CODE------------------------%
clear all;close all;clc
format long
fid=fopen('50112.txt');
fulltext=textscan(fid,'%s','delimiter','\n');
numberofgridpoints=length(fulltext{1});
fclose(fid);
n=numberofgridpoints/200;
fid=fopen('50112.txt');
datamatrix=fscanf(fid,'%f%f%f%f',[4,inf]);
%-------stroing of velocity data -----------%
for i=1:200
c=i-1;
for j=1:n
d=(c*n)+j;
x(j)=datamatrix(1,j);
y(j)=datamatrix(2,j);
u(i,j)=datamatrix(3,d);
v(i,j)=datamatrix(4,d);
end
end
%*********************************************%
%-------Proper Orthogonal Decompostion--------%
%*********************************************%
%---Calcalating the covarience matrix---------%
c1=u*u';
c2=v*v';
c=(c1+c2)/200;
[beta, lmd]=svd(c);
phix=u'*beta;
phiy=v'*beta;
for j=1:200
phinor=0;
for i=1:n
phinor=phinor+phix(i,j)^2+phiy(i,j)^2;
end
phinor=sqrt(phinor);
phix(:,j)=phix(:,j)/phinor;
phiy(:,j)=phiy(:,j)/phinor;
end
timecoeu=u*phix;
timecoev=v*phiy;
timecoe=timecoeu+timecoev;
%---------velocity recosntruction------------%
for i=1:n
for j=200
meanu(i,j)=0;
coherentu(i,j)=0;
transitionu(i,j)=0;
turbulentu(i,j)=0;
meanv(i,j)=0;
coherentv(i,j)=0;
transitionv(i,j)=0;
turbulentv(i,j)=0;
tvmean(i,j)=0;
tvcoherentv(i,j)=0;
tvtransition(i,j)=0;
tvturbulent(i,j)=0;
end
end
for i=1:200
for j=1:1
meanu(:,i)=timecoe(i,j)*phix(:,j)+meanu(:,i);
meanv(:,i)=timecoe(i,j)*phiy(:,j)+meanv(:,i);
end
end
for i=1:200
for j=2:9
coherentu(:,i)=timecoe(i,j)*phix(:,j)+coherentu(:,i);
coherentv(:,i)=timecoe(i,j)*phiy(:,j)+coherentv(:,i);
end
end
for i=1:200
for j=10:186
transitionu(:,i)=timecoe(i,j)*phix(:,j)+ transitionu(:,i);
transitionv(:,i)=timecoe(i,j)*phiy(:,j)+ transitionv(:,i);
end
end
for i=1:200
for j=187:200
turbulentu(:,i)=timecoe(i,j)*phix(:,j)+ turbulentu(:,i);
turbulentv(:,i)=timecoe(i,j)*phiy(:,j)+ turbulentv(:,i);
end
end
%-----------CYCLE 1------------%
subplot(4,2,1)
tvmean(:,1)=sqrt(meanu(:,1).^2+meanv(:,1).^2);
tvmeanpart=reshape(tvmean(:,1),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvmeanpart,100,'linestyle','none')
hold on
quiver(x,y,meanu(:,1).',meanv(:,1).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('mean part (#1)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,3)
tvcoherent(:,1)=sqrt(coherentu(:,1).^2+coherentv(:,1).^2);
tvcoherentpart=reshape(tvcoherent(:,1),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvcoherentpart,100,'linestyle','none')
hold on
quiver(x,y,coherentu(:,1).',coherentv(:,1).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('coherent part (#1)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,5)
tvtransition(:,5)=sqrt(transitionu(:,5).^2+transitionv(:,5).^2);
tvtransitionpart=reshape(tvtransition(:,5),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvtransitionpart,100,'linestyle','none')
hold on
quiver(x,y,transitionu(:,5).',transitionv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('transition part (#1)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,7)
tvturbulent=sqrt(turbulentu(:,1).^2+turbulentv(:,1).^2);
tvturbulentpart=reshape(tvturbulent,[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvturbulentpart,100,'linestyle','none')
hold on
quiver(x,y,turbulentu(:,1).',turbulentv(:,1).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('turbulent part (#1)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
%----------END of CYCLE 1-------%
%-----------CYCLE 5------------%
subplot(4,2,2)
tvmean(:,5)=sqrt(meanu(:,5).^2+meanv(:,5).^2);
tvmeanpart=reshape(tvmean(:,5),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvmeanpart,100,'linestyle','none')
hold on
quiver(x,y,meanu(:,5).',meanv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('mean part (#5)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,4)
tvcoherent(:,5)=sqrt(coherentu(:,5).^2+coherentv(:,5).^2);
tvcoherentpart=reshape(tvcoherent(:,5),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvcoherentpart,100,'linestyle','none')
hold on
quiver(x,y,coherentu(:,5).',coherentv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('coherent part (#5)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,6)
tvtransition(:,5)=sqrt(transitionu(:,5).^2+transitionv(:,5).^2);
tvtransitionpart=reshape(tvtransition(:,5),[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvtransitionpart,100,'linestyle','none')
hold on
quiver(x,y,transitionu(:,5).',transitionv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('transition part (#5)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
subplot(4,2,8)
tvturbulent=sqrt(turbulentu(:,5).^2+turbulentv(:,5).^2);
tvturbulentpart=reshape(tvturbulent,[13,20]);
[X,Y]=meshgrid(397:32:1005,157:32:541);
contourf(X,Y,tvturbulentpart,100,'linestyle','none')
hold on
quiver(x,y,turbulentu(:,5).',turbulentv(:,5).','color','black');
set(gca,'ydir','reverse');
xlabel('x (mm)','fontweight','normal','fontsize',8)
ylabel('y (mm)','fontweight','normal','fontsize',8)
title('turbulent part (#5)','fontweight','bold','fontsize',9)
axis on
axis tight
hold off
c = colorbar;
c.Label.String = 'V [m/s]'
c.Label.FontSize =8;
c.FontWeight = 'normal'
%----------END of CYCLE 5-------%

Matt J on 26 Apr 2021
##### 2 CommentsShowHide 1 older comment
Matt J on 27 Apr 2021
If I simply do a global search/replace in your code, changing "subplot" to "subaxis", I get the following,