how to plot two graphs in one plot

6 ビュー (過去 30 日間)
HARIKRISHNA B YADULADODDI
HARIKRISHNA B YADULADODDI 2021 年 4 月 23 日
コメント済み: Adam Danz 2021 年 4 月 27 日
I have created the following plot but i want to reverse the y direction(i,e top left corner should start with 50 in y direction) but if i reverse the y direction the vectors will point in downward direction and i dont want the vectors to point in downward direction if i reverse the y direction kindly help me . .
5 件のコメント
Adam Danz
Adam Danz 2021 年 4 月 24 日
HARIKRISHNA B YADULADODDI 's duplicate question moved here
The Y-axis ticks go like 0,5,10- - - - - 50
I want the plot to remain as it is, but flip the ticks so that they go like 50 45 40 - - - - - - 5,0.
Can this be done? please find the code and file for reference.
clearall;closeall;clc
formatlong
%--------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 velocity-----------%
fori=1:200
c=i-1;
forj=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
x1(1:13,1:20)=0;
y1(1:13,1:20)=0;
a=-19;
b=10;
forj=1:20
fori=1:13
x1(i,j)=a;
end
a=a+2;
end
x1=reshape(x1,1,260)
fori=1:13
forj=1:20
y1(i,j)=b;
end
b=b+1.92307692307;
end
y1=reshape(y1,1,260)
%-----------Ensemble mean------------%
addu(1:n)=0;
addv(1:n)=0;
forj=1:n
fori=1:200
addu(1,j)=addu(1,j)+u(i,j);
addv(1,j)=addv(1,j)+v(i,j);
end
avgu(1,j)=addu(1,j)/200;
avgv(1,j)=addv(1,j)/200;
end
%---------------------plot--------%
figure('name','ENSEMBLE AVARAGE FOR 50112')
rectangle('Position',[-26.75 0 53.55 50]);
xlabel('x (mm)')
ylabel('y (mm)')
axisequal
axis ([-25 25 0 50])
set(gca,'ytick',0:10:50)
axistight
holdon
rectangle('Position',[-26.75 40 53.5 5],'FaceColor',[0.502 0.502 0.502])
text (-2.5,42.5,'Piston','Color','black','FontSize',14)
y=yline(1.2,'r','TDC')
y.LineWidth = 1;
y.LabelHorizontalAlignment='center'
y.LabelVerticalAlignment='middle'
holdon
magnitude=sqrt(avgu.^2+avgv.^2);
magnitude=reshape(magnitude,[13,20]);
[X,Y]=meshgrid(-19:2:19,10:1.9230769:33.0769230);
contourf(X,Y,magnitude,100,'linestyle','none')
holdon
h=quiver(x1,y1,avgu,avgv,'color','black');
set(gca,'ydir',“反向”)
axisequal
c = colorbar;
c.Label.String ='V [m/s]'
c.Label.FontSize =14;
c.FontWeight ='normal'
holdoff
output: [ see figure in main question ]

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

採用された回答

Adam Danz
Adam Danz 2021 年 4 月 24 日
編集済み:Adam Danz 2021 年 4 月 24 日
You're reversing the y-axis with this line in your code.
set(gca,'ydir',“反向”)
If you want the y-axis direction to be normal but leave the contour and quiver plots in their current orientation, that means the data are in the wrong order. Ideally you would alter the code so that the matrices and vectors are constructed in the correct order. Bu here's a way to flip the data as it is.
  1. Remove the line that reverses the y-direction of the y-axis.
  2. Flip the y-coordinates for the contour plot (see below)
  3. Flip the y-coordinatesandthe y-vector-component of the quiver plots in polar coordinates (see below)
Step 2:
Y = flipud(Y);% <--- add this
contourf(X,Y,magnitude,100,'linestyle','none')
Step 3:
fori=1:13
forj=1:20
y1(i,j)=b;
end
b=b+1.92307692307;
end
y1 = flipud(y1);% <--- add this
y1=reshape(y1,1,260)
。..
。..
。..
[theta, radius] = cart2pol(avgu,avgv);% <--- add this
[avgu, avgv] = pol2cart(-theta, radius);% <--- add this
h=quiver(x1,y1,avgu,avgv,'color','black');
Result
6 件のコメント
Adam Danz
Adam Danz 2021 年 4 月 27 日
Great!!
Here's what I did with the attached data. Look for the 5 leftward arrows " % <------ "
%--------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 velocity-----------%
fori=1:200
c=i-1;
forj=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
x1(1:13,1:20)=0;
y1(1:13,1:20)=0;
a=-19;
b=10;
forj=1:20
fori=1:13
x1(i,j)=a;
end
a=a+2;
end
x1=reshape(x1,1,260);
fori=1:13
forj=1:20
y1(i,j)=b;
end
b=b+1.92307692307;
end
y1 = flipud(y1);% <------ ADD THIS
y1=reshape(y1,1,260);
%-----------Ensemble mean------------%
addu(1:n)=0;
addv(1:n)=0;
forj=1:n
fori=1:200
addu(1,j)=addu(1,j)+u(i,j);
addv(1,j)=addv(1,j)+v(i,j);
end
avgu(1,j)=addu(1,j)/200;
avgv(1,j)=addv(1,j)/200;
end
%---------------------plot--------%
figure('name','ENSEMBLE AVARAGE FOR 50112')
rectangle('Position',[-26.75 0 53.55 50]);
xlabel('x (mm)')
ylabel('y (mm)')
axisequal
axis ([-25 25 0 50])
set(gca,'ytick',0:10:50)
axistight
holdon
rectangle('Position',[-26.75 40 53.5 5],'FaceColor',[0.502 0.502 0.502])
text (-2.5,42.5,'Piston','Color','black','FontSize',14)
y=yline(1.2,'r','TDC');
y.LineWidth = 1;
y.LabelHorizontalAlignment='center';
y.LabelVerticalAlignment='middle';
holdon
magnitude=sqrt(avgu.^2+avgv.^2);
magnitude=reshape(magnitude,[13,20]);
[X,Y]=meshgrid(-19:2:19,10:1.9230769:33.0769230);
Y = flipud(Y);% <------ ADD THIS
contourf(X,Y,magnitude,100,'linestyle','none')
holdon
[theta, radius] = cart2pol(avgu,avgv);% <------ ADD THIS
[avgu, avgv] = pol2cart(-theta, radius);% <------ ADD THIS
h=quiver(x1,y1,avgu,avgv,'color','black');
% set(gca,'ydir','reverse') % <------ REMOVE THIS
axisequal
c = colorbar;
c.Label.String ='V [m/s]';
c.Label.FontSize =14;
c.FontWeight ='normal';
holdoff

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

その他の回答 (0 件)

カテゴリ

Find more on2-D and 3-D PlotsinHelp CenterandFile Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by