4

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?

4
  • Couldn't you just ::-1 the map?
    – s.bandara
    Feb 11, 2013 at 21:05
  • Can you be a little more specific. For example could you write this out in simple line of code. Feb 11, 2013 at 21:09
  • docs.enthought.com/chaco/api/… I don't use mlab, but I suspect that the function at that link will do the trick.
    – tacaswell
    Feb 11, 2013 at 21:15
  • I would also be careful about invert vs reverse terminology. Invert could also mean (r, g, b) -> float.
    – tacaswell
    Feb 11, 2013 at 21:17

2 Answers 2

12

Using the script recording of the mayavi pipeline, I found :

s.module_manager.scalar_lut_manager.reverse_lut = True
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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.