0

I'm trying to create a color table for Terracotta as described here: https://terracotta-python.readthedocs.io/en/latest/tutorials/custom-colormaps.html.

My goal is to create a colormap that is similar to the following color ramp: enter image description here

The colors are provided via hex codes: enter image description here

I'm hoping that someone can advise the best way to convert this into a colormap that is compatible with Terracotta. At this point, I'm unsure the best way to create the map with stop colors and the only example that the Terracotta team has provided was to create a grayscale color map.

>>> import numpy as np
>>> cmap_data = np.stack((
...     np.arange(0, 255, dtype='uint8'),
...     np.arange(0, 255, dtype='uint8'),
...     np.arange(0, 255, dtype='uint8'),
...     np.full(255, 255, dtype='uint8')
... ), axis=1)
>>> np.save('mycmap_rgba.npy', cmap_data)
Craytor
  • 117
  • 11

1 Answers1

0

For anyone else wondering how to solve this, you can use matplotlib's colormaps to generate the array of color values for you.

import matplotlib
import numpy as np

colorsList = ['#FFFFFF','#B4FFB9','#00F42F','#05B118','#007000','#FFEC00','#F08500','#E40000','#680006','#141414','#A7A7A7','#FAFAFA']

CustomCmap = matplotlib.colors.LinearSegmentedColormap.from_list('mycmap',colorsList)

x = np.linspace(0, 1, 255)
cmap_vals = CustomCmap(x)
cmap_uint8 = (cmap_vals * 255).astype('uint8')

np.save('mycmap_rgba.npy', cmap_uint8)

Documentation for matplotlib's color tables is available here.

Craytor
  • 117
  • 11