【发布时间】:2023-03-17 22:35:01
【问题描述】:
我正在尝试绘制一个 3D 曲面,该曲面构造为适合 python 中的一些 {x,y,z} 点——理想情况下类似于 Mathematica ListSurfacePlot3D 函数。到目前为止,我在我的观点上尝试了 plot_surface 和 plot_wireframe 无济于事。
只有坐标区使用plot_surface 渲染。 plot_wireframe 给出了一堆 squigglys,模糊地呈现对象的形状,但不是文档中显示的漂亮类型:
与ListSurfacePlot3D 的结果比较:
这是一个最小的工作示例,使用我发布的 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)
那么,要么
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:
【问题讨论】:
-
plot_surface和plot_wireframe到底有什么问题? -
@ali_m 只是用
plot_surface渲染的轴(我得到了一个无法描述的Visual C++ 运行时错误)。plot_wireframe给出了一堆波浪线,模糊地呈现对象的形状,但不是文档中显示的那种很好的类型。 -
@Marcin 很难获得 MWE,因为我无法共享我正在尝试绘制的数据集,抱歉。我可以使用
scatter绘制点,所以我很确定我已经正确设置了其他东西。 -
你能创建一些相同格式的虚拟数据吗?或者至少显示代码?
-
@Marcin 我正在尝试查看是否可以生成一些我可以共享的数据/有意义的代码。
标签: python 3d matplotlib