mixing colormap and explicit colors

Hey folks,

I cannot find any way in bokeh to get the color for a value from a colormap.

Colormap
calculation seems to happen on the javascript side during page load, and there is no correspondig implementation in python. Is that so?

My particular issue is:

I’m plotting rectangles, and I need some of them to be colored from a colormap, others to be colored with listed values.

Turning everything into a list of explicitly stated colors seems like the logical thing, but for that I need to get some of the colors for the rectangles from the colormap.

Another way would be to call .rect() twice, treating the points as separate datasets. But that can be, and in my case would be, quite inconvenient.

Cheers,

ale
.~´

Hi,

It is correct that Bokeh colormapping happens only on the JS side. It sounds like you will want to color map explicitly in python yourself. A basic linear colormapping scales the data to the palette size, then uses that result to index into the palette:

  index = floor( (value - min) / (max - min) )
  color = palette[index]

There can be some minor variations or subtleties handling boundary values, but that's the basic idea. If you'd like to compare to the exact JS code, it is located here:

  https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/mappers/linear_color_mapper.ts#L25-L62

Thanks,

Bryan

···

On Apr 6, 2018, at 10:14, Ale Abdo <[email protected]> wrote:

Hey folks,

I cannot find any way in bokeh to get the color for a value from a colormap.

Colormap calculation seems to happen on the javascript side during page load, and there is no correspondig implementation in python. Is that so?

My particular issue is:

I'm plotting rectangles, and I need some of them to be colored from a colormap, others to be colored with listed values.

Turning everything into a list of explicitly stated colors seems like the logical thing, but for that I need to get some of the colors for the rectangles from the colormap.

Another way would be to call .rect() twice, treating the points as separate datasets. But that can be, and in my case would be, quite inconvenient.

Cheers,

ale
.~´

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/4a2a7e08-ea1f-4589-9f3a-b374eef14837%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.