Help needed to make a 3d contour plot

5 次查看(过去 30 天)
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.
As an example to clear things up, this is what I want to plot.
  2 个评论
KSSV
KSSV 2017-3-16
First, are you able to plot the surface with the data given?
Digvijay Rawat
Digvijay Rawat 2017-3-16
No, I am not being able to figure out how to make a usrface out of all the points. Functions like scatter3 and plot 3 plot all the points but I would want a surface through all those points. Could you suggest any way to do so?

请先登录,再进行评论。

回答(1 个)

Divyajyoti Nayak
Divyajyoti Nayak 2024-9-13
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:
'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);
Warning: Duplicate data points have been detected and removed.
[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!

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by