我正在尝试绘制一些实验数据,而我正面临着三角测量的问题,正如更详细地解释here。我发现解决方案可能是将网格从xy更改为xz,并使用y作为高程。
但是我没有关于这种可能性的信息。那么有没有办法这样做,可能通过使用一些掩码或一些滤波器来反转三角测量的y和z列?
这是一个基本代码:
import numpy
from mayavi import mlab
X2 = numpy.array([0, 0, 1, 1])
Y2 = numpy.array([0.5, 0.45, 1, 0.5])
Z2 = numpy.array([0, 1, 0.5,0])
fig = mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5))
# Define the points in 3D space
# including color code based on Z coordinate.
pts = mlab.points3d(X2, Y2, Z2, Y2, colormap='jet')
# Triangulate based on X, Y with Delaunay 2D algorithm.
# Save resulting triangulation.
mesh = mlab.pipeline.delaunay2d(pts)
# Remove the point representation from the plot
pts.remove()
# Draw a surface based on the triangulation
surf = mlab.pipeline.surface(mesh, colormap='jet')
# Simple plot.
mlab.outline(extent=(0,1,0,1,0,1))
mlab.axes(extent=(0,1,0,1,0,1))
mlab.show()
答案 0 :(得分:1)
您可以使用SciPy的Delaunay算法独立于数据的顺序。 triangular_mesh()
允许您为色图指定标量:
import numpy as np
from scipy.spatial import Delaunay
from mayavi import mlab
X2 = np.array([0, 0, 1, 1])
Y2 = np.array([0.5, 0.45, 1, 0.5])
Z2 = np.array([0, 1, 0.5,0])
# use scipy for delaunay:
p2d = np.vstack([X2,Y2]).T
d2d = Delaunay(p2d)
fig = mlab.figure(1, bgcolor=(1, 0.7, 1), fgcolor=(0.5, 0.5, 0.5))
# Generate triangular Mesh:
tmesh = mlab.triangular_mesh(X2, Y2, Z2, d2d.vertices,
scalars=Y2, colormap='jet')
# Simple plot.
mlab.outline(extent=(0,1,0,1,0,1))
mlab.axes(extent=(0,1,0,1,0,1))
mlab.show()