I simply want to know how to invert a colormap in mlab. I know in matplotlib you can simply add _r to the name of the colormap to invert the color scheme. However it appears to be slightly different in mlab. Does anyone know how this can be achieved?
Asked
Active
Viewed 1,985 times
4
-
Couldn't you just `::-1` the map? – s.bandara Feb 11 '13 at 21:05
-
Can you be a little more specific. For example could you write this out in simple line of code. – user1750948 Feb 11 '13 at 21:09
-
http://docs.enthought.com/chaco/api/mappers.html#chaco.api.ColorMapper.reverse_colormap I don't use `mlab`, but I suspect that the function at that link will do the trick. – tacaswell Feb 11 '13 at 21:15
-
I would also be careful about invert vs reverse terminology. Invert could also mean `(r, g, b) -> float`. – tacaswell Feb 11 '13 at 21:17
2 Answers
12
Using the script recording of the mayavi pipeline, I found :
s.module_manager.scalar_lut_manager.reverse_lut = True

recursix
- 333
- 2
- 9
3
I guess you want to reverse a colormap. Here is what works for me (it might not be the easiest solution, i am not an expert on mayavi), modified from here
s=mlab.surf(xx,yy,zz,colormap='GnBu')
lut = s.module_manager.scalar_lut_manager.lut.table.to_array()
ilut = lut[::-1]
# putting LUT back in the surface object
s.module_manager.scalar_lut_manager.lut.table = ilut
# forcing to update the figure once we have changed the LUT
mlab.draw()
mlab.view()

sangita
- 74
- 3