question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add 256-color palettes, add a function to generate diverging palettes

See original GitHub issue

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.

reds

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

palettes256

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.

diverging1

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).

diverging2

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Oct 10, 2019

@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

1reaction
russellburdtcommented, Sep 27, 2019

@bryevdv Got that, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bokeh.palettes — Bokeh 3.0.3 Documentation
A Bokeh palette comprised of the Bokeh shutter logo colors. Palettes designed for color-deficient usability. Additionally, you can also use any of the...
Read more >
Setting up Color Palettes in R
To create a RColorBrewer palette, use the brewer.pal function. It takes two arguments: n , the number of colors in the palette; and...
Read more >
Create Custom Color Palettes - Tableau Help
You can add as many custom palettes as you like to your Preferences.tps file, each with as many colors as you ... Create...
Read more >
Chapter 25 Using colors in R - STAT 545
The command data("dalton") will make two objects available which represent a 256-color palette as it would appear with normal vision, with two types...
Read more >
List of software palettes - Wikipedia
Each palette is represented by an array of color patches. A one-pixel size version appears below each palette, to make it easy to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found