python – 具有不同大小和颜色的Mayavi points3d
作者:互联网
mayavi是否可以单独指定每个点的大小和颜色?
那个API对我来说很麻烦.
points3d(x, y, z...)
points3d(x, y, z, s, ...)
points3d(x, y, z, f, ...)
x, y and z are numpy arrays, or lists, all of the same shape, giving the positions of the points.
If only 3 arrays x, y, z are given, all the points are drawn with the same size and color.
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.
因此,在这种情况下,标量控制大小和颜色,并且不可能解开它们.我想要一种方法将大小指定为(N,1)数组,并将颜色指定为另一个(N,1)数组.
看起来很复杂?
解决方法:
每个VTK源都有一个标量和向量的数据集.
我在我的程序中使用的技巧是使颜色和大小不同是绕过mayavi源并直接在VTK源中,使用标量颜色和矢量大小(它可能反过来也适用).
nodes = points3d(x,y,z)
nodes.glyph.scale_mode = 'scale_by_vector'
#this sets the vectors to be a 3x5000 vector showing some random scalars
nodes.mlab_source.dataset.point_data.vectors = np.tile( np.random.random((5000,)), (3,1))
nodes.mlab_source.dataset.point_data.scalars = np.random.random((5000,))
您可能需要转置5000×3矢量数据或以其他方式移动矩阵尺寸.
标签:vtk,mayavi,python,data-visualization 来源: https://codeday.me/bug/20191007/1867518.html