Can I plot a colorbar for a bokeh heatmap?

bs123 picture bs123 · Sep 16, 2015 · Viewed 9.4k times · Source

Does bokeh have a simple way to plot the colorbar for a heatmap?

In this example it would be a strip illustrating how colors correspond to values.

In matlab, its called a 'colorbar' and looks like this: enter image description here

Answer

birdsarah picture birdsarah · Sep 16, 2015

UPDATE: This is now much easier: see

http://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#color-bars


I'm afraid I don't have a great answer, this should be easier in Bokeh. But I have done something like this manually before.

Because I often want these off my plot, I make a new plot, and then assemble it together with something like hplot or gridplot.

There is an example of this here: https://github.com/birdsarah/pycon_2015_bokeh_talk/blob/master/washmap/washmap/water_map.py#L179

In your case, the plot should be pretty straight forward. If you made a datasource like this:

| value | color
| 1     | blue
.....
| 9     | red

Then you could do something like:

legend = figure(tools=None)
legend.toolbar_location=None
legend.rect(x=0.5, y='value', fill_color='color', width=1, height=1, source=source)
layout = hplot(main, legend)
show(legend)

However, this does rely on you knowing the colors that your values correspond to. You can pass a palette to your heatmap chart call - as shown here: http://docs.bokeh.org/en/latest/docs/gallery/cat_heatmap_chart.html so then you would be able to use that to construct the new data source from that.

I'm pretty sure there's at least one open issue around color maps. I know I just added one for off-plot legends.