themachinist themachinist - 1 year ago 68
Python Question

I would like to remove the first n colors from a colormap without losing the original number of colours

from matplotlib import cm
import seaborn as sns
import matplotlib.pyplot as plt

Here is the original colormap

cmap = [cm.inferno(x)[:3] for x in range(0,256)]

enter image description here

My preferred outcome is something along the lines the colormap shown below, except with original number of colours

cmap2 = [cm.inferno(x)[:3] for x in range(0,256)][100:]

enter image description here

Answer Source

I believe that by "same resolution" you mean that you want 256 colors in the palette. I would actually think of this as having a different resolution from the original palette in sense that the values are closer together in the color space. In any case, I think you can get what you want by doing:

import numpy as np
import seaborn as sns
from matplotlib import cm

x = np.linspace(.3, 1, 256)
pal = cm.inferno(x)

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download