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

12 ビュー (過去 30 日間)
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
%--------Reading velocity data-------%
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-------%
  9 件のコメント
HARIKRISHNA B YADULADODDI
HARIKRISHNA B YADULADODDI 2021 年 4 月 26 日
Thank you for your reply @Adam Danz @the cyclist @DGM. Please help in reducing the space between plot in horizontal direction. Kindly find my code and data file above.
@DGM How would you manually resize the window to do that. Could your please provide the more information on that.
@Adam Danz i tried all the possible ways i could but the space is not reducing.
@Adam Danz @the cyclist @DGM. Please help in reducing the space between plot in horizontal direction. Kindly find my code and data file above.
DGM
DGM 2021 年 4 月 26 日
I resized the figure window by clicking on the corner and dragging it.

サインインしてコメントする。

回答 (2 件)

the cyclist
the cyclist 2021 年 4 月 23 日
編集済み: Adam Danz 2021 年 4 月 26 日
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.
  6 件のコメント
Adam Danz
Adam Danz 2021 年 4 月 26 日
編集済み: Adam Danz 2021 年 4 月 26 日
@HARIKRISHNA B YADULADODDI if you really want to optimize space, it looks like axes within each row use the same color scale so you could eliminate the colorbars on the left.
Also, it looks like all axes have the same limits so you could remove axis ticks for all axes except the ones on the left and bottom.
% quick demo
f1 = figure();
tlo = tiledlayout(f1,4,2,'Padding','compact','TileSpacing','none');
x = linspace(400,1000,500);
y = linspace(250,550,500);
xr = linspace(-2*pi,2*pi,numel(x));
yr = linspace(0,4*pi,numel(y));
[xm,ym] = meshgrid(xr,yr);
Z = sin(xm) + cos(ym);
ax = gobjects(1,8);
for i = 1:8
ax(i) = nexttile(tlo);
contourf(ax(i),x,y,Z,10)
axis(ax(i),'tight')
axis(ax(i),'equal')
if mod(i,2)==0
colorbar(ax(i))
end
end
f1.UserData.lp(1) = linkprop(ax(1:6),'clim');
f1.UserData.lp(2) = linkprop(ax(7:8),'clim');
f1.UserData.lp(3) = linkprop(ax,{'xlim','ylim'});
set(ax(2:2:end-2),'xtick',[],'ytick',[])
set(ax(end),'ytick',[])
set(ax(1:2:end-3),'xtick',[])
set(ax(end-1:end),'XTick',ax(end).XTick(1:end-1)) % only needed of last tick is in the way
f1.Position(3:4) = [540,500];
movegui(f1)
title(tlo,'TiledLayout')
annotation(f1,'rectangle',[0 0 1 1], 'Color','k','LineWidth',4) %show fig edges
HARIKRISHNA B YADULADODDI
HARIKRISHNA B YADULADODDI 2021 年 4 月 27 日
@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
%--------Reading velocity data-------%
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
Matt J 2021 年 4 月 26 日
  6 件のコメント
Matt J
Matt J 2022 年 3 月 21 日
@DGM Shouldn't matter. The post has been inactive for long enough that anyone can accept.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeColorbar についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by