MATLAB Answers

How to overlay two surf plots?

25 views (last 30 days)
Hi everyone,
I am trying to overlay the contour stroke shape into the colorful surf plot
Here the code i've tried but it doesnt work, it only show the left image above
hold on
surf(X,Y,-M1); surf(-X,Y,M1); %Reflection along y axis
surf(X,Y,Ta); surf(-X,Y,Ta); %Stroke Contour


Show 1 older comment
LEONG SING YEW on 15 Mar 2020
Hi, i test two of your codes and i found that
surf(X,Y,-M1); surf(-X,Y,M1); %Reflection along y axis
is the same as the
surf(X,Y,-M1); surf(-X,flipud(Y),M1); %Reflection along y axis
hold on
surf(-X,flipud(Y),M1); %surf(X,Y,-M1); %Left image - contour
surf(X,Y,Ta); %right image - stroke contour
Do you have any idea on how to overlay the right image to the left image?
Walter Roberson
Walter Roberson on 15 Mar 2020
It would help if we had your data to work with -- X, Y, and M1 and Ta
LEONG SING YEW on 15 Mar 2020
Yes you may have my code and my data in the csv attachment,
The picture shown is what i'm trying to do: to overlay the black stroke of the flame front on the colorful surf plot
colormap jet
Read data
filename0 = '0.csv';
Data0 = csvread(filename0,6,0);
filename1 = '360.csv';
Data1 = csvread(filename1,6,0);%skip 6 header lines
Data Extraction
X_Data = Data0(:,2); Y_Data = Data0(:,1); %x and y coordinates
%Extract both temperature and x-velocity data
T_Data0 = Data0(:,8); V_Data0 = Data0(:,9);
T_Data1 = Data1(:,8); V_Data1 = Data1(:,9);
V_Data1 = V_Data1-V_Data0; %Fluctuation velocity, v'
V_Data1(T_Data1>400)=0; %Temperature outside the flame front is not considered
T_1=V_Data1-1; %Create flame front stroke by darken it using caxis later, or any alternative method
T_1(T_Data1>500)=NaN; T_1(T_Data1<325)=NaN; %Only circumference of flame front is needed
[x,~,xi]=unique(X_Data*1e3/2); %convert m to mm
subs=[xi yi];%use the indices instead of values as coordinates
[X,Y]=ndgrid(x,y);%generate the grid surf() expects
Ta =accumarray(subs,T_1,[],[],NaN);
M1=accumarray(subs,V_Data1,[],[],NaN);%fill missing with NaN
hold on
surf(-X,Y,M1); surf(X,Y,-M1); %Reflection along y-axis
surf(-X,Y,Ta); surf(X,Y,Ta); %Stroke Contour
shading interp; c=colorbar;
xlim([-2 2]); ylim([-0.5 3.4]);
xlabel("x/R (mm)"+newline);ylabel("y/R (mm)"+newline)
title('Phase = 0\circ')
caxis([-.1 .1]) %Set the range

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 16 Mar 2020


Show 1 older comment
LEONG SING YEW on 22 Mar 2020
I use xy plots instead of using the the surf plot for the contour line for better view.
The images attached below can be seen that the surf image is blocking the stroke shape on each side, i wonder if the xy plot stroke shape can be shift towards/backward so it can overlay the surf plot. Appreciate your help again.
Here's the code:
T_Data1(T_Data1>390) = 300;
[A B]=size(T_Data1);
X_new = zeros(A,1); Y_new = zeros(A,1);
for i = 1:A;
if T_Data1(i,:)>350;
X_new(i) = X_Data(i); %retain the value
Y_new(i) = Y_Data(i);
XY = [X_new*1e3 Y_new*1e3];
rows = find(XY(:,2)==0);
XY(rows,:)=[]; %eliminate rows with value zeros
[~,idx] = unique(XY(:,2)); %which rows have a unique first value
XY = XY(idx,:); %retain them
[~,idy] = unique(XY(:,1));
XY = XY(idy,:);
X = XY(:,1)/2;
Y = XY(:,2)/2;
plot(-X,Y,'black','linewidth',2); plot(X,Y,'black','linewidth',2)
Walter Roberson
Walter Roberson on 22 Mar 2020
plot() creates a 3D plot with empty Z components, and that in turn is treated the same as if the Z components were all 0. You can use plot3() to provide explicit Z coordinates; you would want to use a Z larger than the largest Z in the surf plot.
I wonder if pcolor() would be better than surf() for your purpose? pcolor is a surface plot underneath, but it creates a surface in which all the Z are 0 and the color data is set according to the Z data that was passed to pcolor(). Using Z all 0 can make it easier to draw things on top of it.
LEONG SING YEW on 22 Mar 2020
omg, i didn't know this command "pcolor" exist, amazing!!! Thank you so much!!!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by