class nlcmap(LinearSegmentedColormap):
    """A nonlinear colormap"""
name = 'nlcmap'

def __init__(self, cmap, levels):
    self.cmap = cmap
self.monochrome = self.cmap.monochrome
self.levels = asarray(levels, dtype='float64')
self._x = self.levels - self.levels.min()
self._x /= self._x.max()
self._y = linspace(0, 1, len(self.levels))

def __call__(self, xi, alpha=1.0, **kw):
    yi = interp(xi, self._x, self._y)
return self.cmap(yi, alpha)
Nonlinear colormap with Matplotlib