Mayavi points3d具有不同的大小和颜色 [英] Mayavi points3d with different size and colors

查看:328
本文介绍了Mayavi points3d具有不同的大小和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mayavi中是否可以分别指定每个点的大小和颜色?

Is it possible in mayavi to specify individually both the size and the colors of every point?

该API对我来说很麻烦。

That API is cumbersome to me.

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)的方法

So in this case scalar controls both the size and the color and it's not possible to disentangle them. I want a way to specify size as a (N,1) array and color as another (N,1) array individually..

似乎很复杂?

推荐答案

每个VTK源具有标量和向量的数据集。

Each VTK source has a dataset for both scalars and vectors.

我在程序中使用的使颜色和大小不同的技巧是绕过mayavi源并直接在VTK中来源,使用标量表示颜色,使用向量表示大小(也可能使用相反的方法)。

The trick I use in my program to getting the color and size to differ is to bypass the mayavi source and directly in the VTK source, use scalars for color and vectors for size (it probably works the other way around as well).

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,))

您可能需要转置5000x3矢量数据或以其他方式移动矩阵尺寸不知何故

You may need to transpose the 5000x3 vector data or otherwise shift the matrix dimensions somehow.

这篇关于Mayavi points3d具有不同的大小和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆