Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color format accepted by Bokeh plots

Tags:

python

bokeh

In many Bokeh examples (e.g. the unemployment chart, and the periodic table), I see that the plotting primitive rect receives color from ColumnDataSource from an HTML representation:

e.g.:

....

colors = [
    "#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce",
    "#ddb7b1", "#cc7878", "#933b41", "#550b1d"
]

source = ColumnDataSource(
    data=dict(month=month, year=year, color=color, rate=rate)
)

p.rect("year", "month", 1, 1, source=source,
    color="color", line_color=None)

However, looking at the documentation of rect, I don't see a parameter for color (note that you are allowed to pass "line-properties" and "fill-properties" parameters, but none of them accept color as a parameter)

Most importantly for this question, is there a different way, other than HTML, to specify colors for Bokeh plots? Ideally, I would like to specify colors using the color palettes generated by seaborn.

like image 457
Amelio Vazquez-Reina Avatar asked Dec 24 '14 16:12

Amelio Vazquez-Reina


People also ask

What is a bokeh plot?

The bokeh. plotting API is Bokeh's primary interface, and lets you focus on relating glyphs to data. It automatically assembles plots with default elements such as axes, grids, and tools for you.

How do I get rid of gridlines in bokeh?

You can hide the lines by setting their grid_line_color to None .


1 Answers

color is a convenience argument to the plot glyph methods that sets both line_color and fill_color at the same time. Those are the actual arguments, in case you'd rather use them for explicitness, or need to set them independently.

There is also now a LinearColorMapper object that you can configure with one of the palettes in bokeh.palettes or with your own sequence of colors. You can use this from python to map data into the list of colors for the ColumnDataSource.

Note that in an upcoming release (probably 0.8) you will be able to specify a palette/colormapper + column name for the color (or line_color or fill_color) arguments, and then the color mapping will happen on the client (instead of having to send over the possibly large list of colors explicitly)

like image 97
bigreddot Avatar answered Oct 11 '22 14:10

bigreddot