How to use only part of a colormap without redim.range()?

Based on this answer, now I think that there is no better way to handle this than to export a list of colors from wherever and import it back. It looks like Bokeh itself only deals with lists, and similarly ,the first thing Holoviews does when gets a matplotlib colormap name is that it converts that to a list, exactly with the process_cmap function mentioned by @ahuang11 .

https://stackoverflow.com/questions/67118061/how-to-get-bokeh-to-interpolate-a-palette-from-3-colors

As of version 2.3.1, palettes are just lists of colors, and currently existing colormappers just use palettes, as given, without modifying them. If you want more colors you would need to interpolate the palette (list of colors) out to whatever size you want before passing it to Bokeh. The “Linear” in LinearColorMapper refers to how values are linearly mapped into the bins defined by a palette.

So to sum up, depending on your needs, these could be the best solutions to get a palette with one (or both) side cut off:

# If you don't mind a busy code but don't want to install/import new dependencies 
# and already use numpy and matplotlib
# this creates a "terrain" palette from 25% to100% with 192 colors inbetween
cmap =  [matplotlib.colors.rgb2hex(c) for c in plt.cm.terrain(np.linspace(0.25, 1, 192))]


# If you want to use it often, it would be easier to create a function and call that every time.
# I've also included the possibility to start with a palette of a few colors and interpolate the rest of the
# colors.
def get_palette(cmap='Greys', n=192, start=0, end=1):
  linspace = np.linspace(start, end, n)
  if isinstance(cmap, list):
    cmap = matplotlib.colors.LinearSegmentedColormap.from_list("customcmap", camp)
    palette = cmap(linspace)
  elif isinstance(cmap, str):
    cmap = matplotlib.pyplot.cm.get_cmap(cmap)
    palette = cmap(linspace)
  else:
    palette = cmap(linspace)

  hex_palette = [matplotlib.colors.rgb2hex(c) for c in palette]
  return hex_palette

cmap = get_palette('terrain', 192, 0.25, 1)
cmap = get_palette(['#FF0000', '#00FF00', '#0000FF'], 192, 0.25, 1)


# If you want to heave shorter code and are okay with installing and importing cmasher
# this creates the exact same result:
import cmasher
cmap = cmasher.get_sub_cmap(plt.cm.terrain, 0.25, 1.0, N=192)

A bit tangential but if anybody reads this I would highly recommend checking out the cmocean colormaps as they are very good perceptually uniform, colorblind-safe, grayscale-printable colormaps. If you install and import the cmocean package, the colormaps are automatically will be available in matplotlib, so for example get_palette('cmo.haline', 192, 0.25, 1) would work just the same. Of course if you only intend to use cmocean colormaps and already importing the module, you can also use its cmocean.tools.crop_by_percent() and cmocean.tools.crop() documented at the link above.