Register the color map cividis for matplotlib, as described in
pip install cividis
After installation, just import cividis
once and it's registered and usable
import cividis
Afterwards, you can use it like any other color map.
import matplotlib.pyplot as pl
import numpy as np
x = np.arange(0, 2*np.pi, 0.07)
y = np.arange(0, 2*np.pi, 0.07)
X, Y = np.meshgrid(x,y)
Z = np.cos(X) * np.sin(Y) * 20
Z += np.random.randn(*Z.shape)
pl.figure(figsize=(4,3.375))
pl.imshow(Z,cmap='cividis')
pl.colorbar()
pl.gcf().savefig('xmpl.png',dpi=150)
pl.show()
This has to be done once in your matplotlibrc
file, or you call the corresponding function from the package.
import cividis
cividis.make_default()
...
pl.imshow(Z)
Will give equal results to the above.
import cividis
color_list = cividis.get_colors(10,n_start=2,n_end=200)
Where the function is implemented as
def get_colors(N, n_start=0, n_end=255):
"""Get a color array of `N` entries, where the `N` entries
are taken at equidistance from the `cividis` array between
`n_start` and `n_end`"""
indices = np.linspace(n_start, n_end, N)
indices = np.array(indices, dtype=int)
return cividis[indices]