0

为了指出我创建的形状对应关系,我想将 3d 网格着色为灰色,除了一些点(例如 1 个点)为红色。这是我当前的代码,不幸的是,将整个图形涂成蓝色,最后一个点涂成红色。 还有我的代码
在此处输入图像描述

mlab.figure()
        part_color = np.full((self.f.shape[0]),0.98)
        part_color[point_idx] = 1
        part_plot = mlab.triangular_mesh(self.part.vx, self.part.vy, self.part.vz, self.part.triv,
                                         scalars=part_color[:, np.newaxis])

这是我的最佳目标(忽略其余的数字,我只想要一些点周围的红球) 在此处输入图像描述

4

1 回答 1

1

您必须为此修改查找表 (LUT)。

我采用了“LUT 修改”示例并根据您的需要对其进行了调整(最高值为红色,其他一切为灰色):

# Create some data
import numpy as np

x, y = np.mgrid[-10:10:200j, -10:10:200j]
z = 100 * np.sin(x * y) / (x * y)

# Visualize it with mlab.surf
from mayavi import mlab
mlab.figure(bgcolor=(1, 1, 1))
surf = mlab.surf(z, colormap='cool')

# Retrieve the LUT of the surf object.
lut = surf.module_manager.scalar_lut_manager.lut.table.to_array()

# The lut is a 255x4 array, with the columns representing RGBA
# (red, green, blue, alpha) coded with integers going from 0 to 255.

# We modify the alpha channel to add a transparency gradient
lut[:] = 255/2 # all grey
# red
lut[-1,0] = 255
lut[-1,1] = 0
lut[-1,2] = 0

lut[:, -1] = 255 # 100% translucency

# and finally we put this LUT back in the surface object. We could have
# added any 255*4 array rather than modifying an existing LUT.
surf.module_manager.scalar_lut_manager.lut.table = lut

# We need to force update of the figure now that we have changed the LUT.
mlab.draw()
mlab.view(40, 85)

喜红色,否则为灰色

于 2019-08-23T18:47:13.813 回答