在MayaVi中为3D点指定绝对颜色 [英] Specify absolute colour for 3D points in MayaVi
问题描述
我正在使用 MayaVi Python库来绘制3d点, points3d
类. 文档指定每个点的颜色通过第四个参数s
:
I am using the MayaVi Python library to plot 3d points, using the points3d
class. The documentation specifies that the colour of each point is specified through a fourth argument, s
:
此外,您可以传递形状与x,y, 和z为每个点或函数给出一个相关的标量值 f(x,y,z)返回标量值.可以使用此标量值 调整点的颜色和大小.
In addition, you can pass a fourth array s of the same shape as x, y, and z giving an associated scalar value for each point, or a function f(x, y, z) returning the scalar value. This scalar value can be used to modulate the color and the size of the points.
这为每个点指定一个标量值,该值将点映射到颜色图,例如copper
,jet
或hsv
.例如.从他们的文档中:
This specifies a scalar value for each point, which maps the point to a colourmap, such as copper
, jet
or hsv
. E.g. from their documentation:
import numpy
from mayavi.mlab import *
def test_points3d():
t = numpy.linspace(0, 4*numpy.pi, 20)
cos = numpy.cos
sin = numpy.sin
x = sin(2*t)
y = cos(t)
z = cos(2*t)
s = 2+sin(t)
return points3d(x, y, z, s, colormap="copper", scale_factor=.25)
赠予:
相反,我想将每个点的实际值指定为(r,g,b)元组.在MayaVi中有可能吗?我曾尝试用元组数组替换s
,但抛出错误.
Instead, I would like to specify the actual value for each point as an (r, g, b) tuple. Is this possible in MayaVi? I have tried replacing the s
with an array of tuples, but an error is thrown.
推荐答案
现在,只需使用color
参数即可完成
This can now simply be done with the color
argument
from mayavi import mlab
import numpy as np
c = np.random.rand(200, 3)
r = np.random.rand(200) / 10.
mlab.points3d(c[:, 0], c[:, 1], c[:, 2], r, color=(0.2, 0.4, 0.5))
mlab.show()
这篇关于在MayaVi中为3D点指定绝对颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!