Help needed to make a 3d contour plot
3 views (last 30 days)
Show older comments
Hello. I have around 50K data points (x,y,z co-ordinates of each point) and the value of a function at each of these points. I want to make a filled contour plot of this function on the 3d surface that would so be formed by joining all the data points. I have tried various functions like contour3, tricontour, scatter3, surf etc but nothing seems to work. If it matters, the value of the function is in no way dependent on the co-ordinates of the point.
2 Comments
Answers (1)
Divyajyoti Nayak
on 13 Sep 2024
Hi Digvijay,
From what I understand, you want to make a 3D surface using x,y,z data points and make a 3D contour plot using function values at these points.
- The ‘surf’ function will help make the surface, but the x,y,z coordinates must be in proper matrix form for it to work. The coordinate data may need to be reshaped if it is in vector format. For more information, please check the documentation of the ‘surf’ function:
- Another way to plot the surface without reshaping the coordinate data is to make use of the ‘alphaShape’ , ‘boundaryFacets’ and ‘trisurf’ functions but, it is important to make sure that all duplicate rows (of x,y,z and function values) be dealt with as the ‘alphaShape’ function automatically deletes them.
Please refer the following documentation links for more knowledge on:
'boundaryFacets': https://www.mathworks.com/help/matlab/ref/alphashape.boundaryfacets.html?s_tid=doc_ta
'trisurf' :
To color the surface according to function values, the ’CData’ property of ‘surf’ and ‘trisurf’ can be used.
Here’s a sample code for both workflows:
clear
clc
t = linspace(0,2*pi,20);
r = 2 + cos(t+pi);
[X,Y,Z] = cylinder(r);
figure(1)
s = surf(X,Z,Y,'FaceColor','interp');
s.CData = Z; %Replace with function values
colormap(jet);
x = reshape(X,[],1);
y = reshape(Y,[],1);
z = reshape(Z,[],1);
shp = alphaShape(x,y,z,1);
[tri,xyz] = boundaryFacets(shp);
figure(2)
colormap(jet);
ts = trisurf(tri,xyz(:,1),xyz(:,3),xyz(:,2),'FaceColor','interp');
ts.CData = xyz(:,3); %Replace with function values
Hope this helps!
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!