用python从{x,y,z}散点数据绘制三维曲面

2024-06-28 19:56:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试绘制一个三维曲面,它被构造成适合python中的某些{x,y,z}点——理想情况下类似于Mathematica^{}函数。到目前为止,我已经尝试了plot_surfaceplot_wireframe关于我的观点,但没有结果。

只有轴使用plot_surface呈现。plot_wireframe给出了一堆模糊的对象形状的曲线,但不是文档中显示的那种好的排序: enter image description here 与来自ListSurfacePlot3D的结果进行比较: enter image description here

下面是一个最小的工作示例,使用我发布的test.csv文件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)

那么,要么

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

或者

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

这就是它使用plot_surface呈现的方式: enter image description here 使用plot_wireframeenter image description here 使用ListSurfacePlot3Denter image description here


Tags: csvfromtestimportplotaxsurfacetemp
1条回答
网友
1楼 · 发布于 2024-06-28 19:56:41

plot_surface期望X,Y,Z值以2D数组的形式出现,正如np.meshgrid返回的那样。当以这种方式对输入进行规则网格化时,plot函数隐式知道曲面中哪些顶点彼此相邻,因此应该与边连接。但是,在您的示例中,您要将一维坐标向量传递给它,因此绘图函数需要能够确定哪些顶点应该连接。

plot_trisurf函数确实通过执行Delaunay三角剖分来处理间距不规则的点,以确定哪些点应以避免“薄三角形”的方式与边连接:

enter image description here

相关问题 更多 >