Skip to content
Advertisement

Bokeh: how to custom scale of ColorBar?

I make a figure (empty to simplify the code but I will add many elements), and a ColorBar to designate the color of different elements.

JavaScript

Now the color bar gives this result:

enter image description here

But I’m not satisfied because I’d like to have a different scale of colors where all positive values are red and all negative values are green. Moreover, I’d like to have defined ticks that will be customized in advance.

  • #465a55: x < -5000
  • #75968f: -5000 < x < -2500
  • #a5bab7: -2500 < x < -1000
  • #c9d9d3: -1000 < x < -500
  • #e2e2e2: -500 < x < 0
  • #dfccce: 0 < x < 500
  • #ddb7b1: 500 < x < 1000
  • #cc7878: 1000 < x < 2500
  • #933b41: 2500 < x < 5000
  • #550b1d: x > 5000

The result would look like this:

enter image description here

Thank you!

Advertisement

Answer

Finally, I found how to custom the ColorBar with predefined values. I changed color palette by multiplying each color by the number corresponding to the interval of the color (for example: #75968f between -5000 and -2500 = 2500):

JavaScript

The mapper is now delimited by defined values, not by min and max elements:

JavaScript

And I changed BasicTicker for FixedTicker so that the ticks correspond well to the limit of each color:

JavaScript

The result:

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement