-1

Note from maintainers: This question as originally posed concerns the obsoleted and removed bokeh.charts API. See Handling Categorical Data for information on Bar cahrts in modern Bokeh


The default color palette used in Bokeh's Bar chart's ColorAttr only has six elements and that poses obvious limitation. Supposedly one can change the Colorattr helper function with same a different palette like Spectral10

But I have a hard time figuring how to apply that to an actual chart. Does anyone have an example of how to do assign a new palette like Spectral10 to the ColorAttr function and then assign the new ColorAttr to a Bar char?

Thanks! SH

bigreddot
  • 33,642
  • 5
  • 69
  • 122

1 Answers1

0

It is actually straightforward, although it is certainly not easy to find in the documentation. You assign the palette with an argument in the Bar chart call:

from bokeh.charts import Bar
from bokeh.palettes import Spectral10

p=Bar( ... ,palette=Spectral10)

If it may be of any use, here is also a code snippet (adapted from other contributors) that I use to generate palettes with an arbitrary number of colors:

import matplotlib.cm as cm
import numpy as np

colormap =cm.get_cmap("jet")
different_colors=15
color_mapping=colormap(np.linspace(0,1,different_colors),1,True)
bokeh_palette=["#%02x%02x%02x" % (r, g, b) for r, g, b in color_mapping[:,0:3]]
Anadyn
  • 81
  • 3