剧情从{X,Y,Z} 3D表面-scatter在Python数据 [英] Plot a 3D surface from {x,y,z}-scatter data in python

查看:706
本文介绍了剧情从{X,Y,Z} 3D表面-scatter在Python数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制构造,以适应某些{X,Y,Z}点蟒蛇3D表面 - 理想有点像数学<一href="http://reference.wolfram.com/mathematica/ref/ListSurfacePlot3D.html"><$c$c>ListSurfacePlot3D功能。到目前为止,我已经试过 plot_surface plot_wireframe 对我的观点无济于事。

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. Thus far I've tried plot_surface and plot_wireframe on my points to no avail.

只有轴渲染 plot_surface plot_wireframe 给出一堆squigglys的,隐约的物体的形状,而不是显示在文档中的漂亮的排序: 比较从结果 ListSurfacePlot3D

Only the axes render with 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: Compare to the result from ListSurfacePlot3D:

下面是一个最小的工作例如,使用test.csv文件我张贴这里

Here is a minimal working example, using a test.csv file I posted here:

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()

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

这是如何呈现使用 plot_surface 并使用 plot_wireframe 并使用 ListSurfacePlot3D

This is how it renders using plot_surface: and using plot_wireframe: and using ListSurfacePlot3D:

推荐答案

plot_surface 预计,X,Y,二维数组的形式Z值,因为会被退回 np.meshgrid 。当输入这种方式定期网格化,积函数隐含知道这在表面顶点彼此相邻,因此应该与边缘接合。在你的榜样,但是,你交给它的坐标的一维向量,所以绘图功能就需要能够找出哪些顶点应该被加入。

plot_surface expects X,Y,Z values in the form of 2D arrays, as would be returned by 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.

plot_trisurf 函数并做Delaunay三角测量法来确定哪个点应该以这样的方式,以避免薄三角形边缘接合处理不规则分布的点:

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':

这篇关于剧情从{X,Y,Z} 3D表面-scatter在Python数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆