bokeh: Add 256-color palettes, add a function to generate diverging palettes
This feature request will modify the bokeh.palettes module to include additional 256-color palettes and a diverging_palette function.
The problem this feature request could be considered to solve is that bokeh 1.3.4 palettes do not currently replicate all of the available matplotlib 3.1.1 palettes.
Color palettes in bokeh are hard-coded as lists of hex color strings. For example,
>>> from bokeh import palettes
>>> palettes.Reds9
['#67000d', '#a50f15', '#cb181d', '#ef3b2c', '#fb6a4a', '#fc9272', '#fcbba1', '#fee0d2', '#fff5f0']
Max size of a palettes.Reds palette in bokeh is 9 which may hide information in a chart where colors encode numbers. A 256-color palette could encode more information.

This feature request will add several 256-color palettes (including but not limited to):

A second component of this feature request is to add a function to the bokeh.palettes module that can return any diverging palette created as a piecewise linear interpolation of fixed palettes.

The diverging_palette function will also support asymmetric diverging palettes, which means the intersection of the two palettes constituting the diverging palette is somewhere other than the middle. This can be useful to create charts where high and low values are mapped to colors asymmetrically (e.g. as in this blog post).

The diverging_palette function can be implemented as in the code below. It is a direct manipulation of input palettes that uses the already-implemented linear_palette function. A ValueError will be raised by the linear_palette function if more colors are requested than are available.
def diverging_palette(palette1, palette2, n=256, midpoint=0.5):
palette2 = palette2[::-1]
n1 = np.round(midpoint * n)
n2 = np.round((1 - midpoint) * n)
return palettes.linear_palette(palette1, n1) + palettes.linear_palette(palette2, n2)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 22 (22 by maintainers)
@russellburdt Just as an FYI, for this to go in 1.4 it would need to be submitted/merged befor the end of next week
@bryevdv Got that, thanks.
@russellburdt Why would a single PR be better? Anyway, I’m not sure because @bryevdv said that using tuples for palettes should coincide with 2.0 and this issue has 1.4 as its milestone.