Hi all,

Does anyone know of a good way to create a new LinearSegmentedColormap based off an existing one?

I have a function which attempts to generate N “optimal” color map indices for a given data array. In cases where the number of values specified in _segmentdata is the same as N, then I can simply copy _segmentdata and modify the indices and create a new color map. In many cases, however, the segment data has far fewer interpolation points, e.g.:

In [52]: cm.gray._segmentdata

Out[52]:

{‘blue’: ((0.0, 0, 0), (1.0, 1, 1)),

‘green’: ((0.0, 0, 0), (1.0, 1, 1)),

‘red’: ((0.0, 0, 0), (1.0, 1, 1))}

Other colormaps may have an arbitrary number of interpolation points. Ideally, what I would like is a way to expand this into N points (e.g. 256) so that I use that as input for my new map.

Any suggestions? I found a similar post from last year, but that doesn’t seem to be applicable in the version of Matplotlib I’m using (1.1.0).

Thanks,

Keith