In matplotlib
the scatterplot offers the possibility of using the color of a plot to indicate value or magnitude like this plot:
For bokeh
, similar examples seem to manually generate the rgb colors, which makes it difficult to produce plots with color scaled by magnitude, esp. wrt. diverging colormaps.
Is it possible to have similar functionality in bokeh
, or to use matplotlib
colormaps to set the color?
It's easy enough to just use
matplotlib
's colormaps directly. For example, the following usesviridis
inbokeh
's example (note that I'm using a jupyter notebook):Essentially, for any matplotlib colormap in
cm
, initializing it with an array of values will return an array with each value replaced by [r,g,b,a] values in the range [0,1]. Note that this assumes all the values are between 0 and 1 as well; here I use matplot.colors.Normalize to ensure this.