pythonplotholoviewshvplot

Subset of colormap in holoviews/hvplot


I have a DataFrame and I want to plot it in a scatter plot with different scatter colors depending on the sample name. I do it for example with:

df.hvplot.scatter(x='x', y='y', color='Sample name', cmap='Reds')

enter image description here

The problem is I would like to have more similar colors among samples, so that they do not span from dark red to almost white, but, let's say, from dark red to red.

So my question is how can I get a subset of the Reds colormap or of any othere holoviews compatible colormap and pass it to the cmap argument to get what I want?


Solution

  • hvPlot accepts Bokeh-style colormaps, which are simple lists of colors, so you can use Python list slicing code like [:128] (take the first half of a 256-color list) on them and then pass the resulting (shorter) list to hvPlot:

    example of python list slicing