specifying absolute RGB colors in mayavi

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

specifying absolute RGB colors in mayavi

Roan LaPlante
Suppose you wanted to plot a surface (or anything) and instead of associating colors with scalar-valued numbers, precisely specify a color for each vertex. There are no examples on the internet that describe how to do this (the most flexible way that is documented is to script into the LUT and define an arbitrary colormap). This is one of the more pressing limitations of mayavi and there are a number of forum posts asking about it.

It turns out, vtk does this quite a bit more easily than I had thought, and you can do it in mayavi with just a bit of hacking around (a minimal example is below).

I would like to fix this, so that the user has a straightforward, traited API to specify RGB or RGBA values (probably, make it so that the scalar trait can be a List(Color)). However, the right design to integrate with what vtk decides to do by default isn't obvious.


from tvtk.api import tvtk; from mayavi import mlab; import numpy as np

x,y,z=np.random.random((3,nr_points)) #some data
colors=np.random.randint(256,size=(100,3)) #some RGB or RGBA colors


#the number of components can be 1 (scalar), 2 (scalar, alpha), 3 (RGB), or 4 (RGBA), this doesnt #need to be specified to use from_array


Roan LaPlante
Athinoula A. Martinos Center for Biomedical Imaging

Enthought-Dev mailing list
[hidden email]