简体   繁体   English

在python中从{x,y,z} - 散射数据绘制3D表面

[英]Plot a 3D surface from {x,y,z}-scatter data in python

I'm trying to plot a 3D surface constructed to fit some {x,y,z} points in python -- ideally something like the Mathematica ListSurfacePlot3D function. 我正在尝试绘制一个3D表面,以适应python中的某些{x,y,z}点 - 理想情况下就像Mathematica ListSurfacePlot3D函数。 Thus far I've tried plot_surface and plot_wireframe on my points to no avail. 到目前为止,我已经在我的观点上尝试了plot_surfaceplot_wireframe无济于事。

Only the axes render with plot_surface . 只有轴使用plot_surface渲染。 plot_wireframe gives a bunch of squigglys, vaguely in the shape of the object, but not the nice sort that is shown in the documentation: plot_wireframe给出了一堆波浪形,模糊地描述了对象的形状,但不是文档中显示的漂亮排序: 在此输入图像描述 Compare to the result from ListSurfacePlot3D : ListSurfacePlot3D的结果进行比较: 在此输入图像描述

Here is a minimal working example, using a test.csv file I posted here : 这是一个最小的工作示例,使用我在这里发布的test.csv文件:

import csv
from matplotlib import pyplot
import pylab
from mpl_toolkits.mplot3d import Axes3D

hFile = open("test.csv", 'r')
datfile = csv.reader(hFile)
dat = []

for row in datfile:
        dat.append(map(float,row))

temp = zip(*(dat))

fig = pylab.figure(figsize=pyplot.figaspect(.96))
ax = Axes3D(fig)

Then, either 然后,要么

ax.plot_surface(temp[0], temp[1], temp[2])
pyplot.show()

or 要么

ax.plot_wireframe(temp[0], temp[1], temp[2])
pyplot.show()

This is how it renders using plot_surface : 这是使用plot_surface渲染的plot_surface 在此输入图像描述 and using plot_wireframe : 并使用plot_wireframe 在此输入图像描述 and using ListSurfacePlot3D : 并使用ListSurfacePlot3D 在此输入图像描述

plot_surface expects X,Y,Z values in the form of 2D arrays, as would be returned by np.meshgrid . plot_surface需要2D数组形式的X,Y,Z值,如np.meshgrid返回的np.meshgrid When the inputs are regularly gridded in this way, the plot function implicitly knows which vertices in the surface are adjacent to one another and therefore should be joined with edges. 当输入以这种方式定期网格化时,绘图函数隐式地知道表面中的哪些顶点彼此相邻,因此应该与边连接。 In your example, however, you're handing it 1D vectors of coordinates, so the plotting function would need to be able to figure out which vertices should be joined. 但是,在您的示例中,您正在处理1D坐标向量,因此绘图函数需要能够确定应该连接哪些顶点。

The plot_trisurf function does handle irregularly spaced points by doing a Delaunay triangulation to determine which points should be joined with edges in such a way as to avoid 'thin triangles': plot_trisurf函数通过执行Delaunay三角剖分来确定哪些点应该与边连接,以避免“薄三角形”,从而处理不规则间隔的点:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python-具有该数据的曲面图的2 / 3D散点图 - Python - 2/3D scatter plot with surface plot from that data 当Z是Python中的列表列表时,如何用X,Y,Z绘制3D曲面? - How to plot 3D surface with X, Y, Z when Z is a list of list in Python? 参数化3D曲面图,颜色取决于(x,y,z) - Parametric 3D Surface Plot with color depending on (x,y,z) (python) 绘制 3d 表面,颜色图为第 4 维,x,y,z 的函数 - (python) plot 3d surface with colormap as 4th dimension, function of x,y,z 给定 x,y,z 坐标的数据,我将如何在 Matplotlib 中制作 3D 表面 plot? - How would I make a 3D surface plot in Matplotlib given this data of x,y,z coordinates? 在 Python 中将常量 x、y、z 线添加到 matplotlib 3D 散点图中 - Add constant x, y , z lines into matplotlib 3D scatter plot in Python 通过 3D x,y,z 散布 plot 数据拟合一条线 - Fitting a line through 3D x,y,z scatter plot data 如何从 Plotly 中的 X、Y、Z 数组绘制 3D 表面? - How to plot a 3D surface from X,Y,Z array in Plotly? 3D表面图,其中z是采用由x和y形成的向量的函数 - 3D Surface Plot where z is a function that takes a vector formed from x and y Python-如何在表面离散3D点(x,y,z)之后从给定的x,y获取z值 - Python - How to get z value from given x, y after surface discrete 3D points (x,y,z)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM