Matplotlib colormap on a mayavi mesh

569 views Asked by At

I would like to use a colormap from matplotlib which is not integrated on mayavi, for printing some 3D figures. The colormap in question is "cividis" and, after trying many different things, I'me not able to do it. What I need is to have that colormap available for plotting a mlab.mesh

Any help is welcome! Thanks

1

There are 1 answers

0
lopsided On

I just had a very similar problem but with plot3d, and found a couple of links useful: https://gist.github.com/scholich/a1b0142acfbad4420575 and https://docs.enthought.com/mayavi/mayavi/auto/example_custom_colormap.html

My solution looked like this:

import numpy as np
from mayavi import mlab
import matplotlib.pyplot as plt

cmap = plt.get_cmap('viridis')
cmaplist = np.array([cmap(i) for i in range(cmap.N)]) * 255
x, y, z = X.T  # X is an array representing a trajectory in 3D space
t = np.linspace(0, 1, len(X))
pts = mlab.plot3d(x, y, z, t)
pts.module_manager.scalar_lut_manager.lut.table = cmaplist

Hopefully this will help you.