Styling Bokeh charts

Is it possible to style Bokeh charts with the same range of styling options as plots made using the plotting interface?

Specifically, I’d like to change the colors, opacity, number of ticks, grid attributes, border attributes etc. on a chart made using the Bar function.

Any help would be great.

-Nik

A lot of the intention of charts is that for most cases you shouldn’t have to worry so much about all the styling details. If you want absolute control over application of colors, etc, then I’d suggest using the lower level interface.

Two things are important to note:

First, that charts produces is a Chart, which subclasses Plot. So, in the end you have the same result, a plot with GlyphRenderers. There will likely be some internal refactoring here soon so that the output provides the maximum flexibility and compatibility possible. So, once you get the output, you can manipulate the plot however you’d like.

Second, the approach with the new charts is to automatically handle the “mapping” of a palette (or anything really) to unique values in one or more columns (df[[‘col1’, ‘col2’]].drop_duplicates()). So, if you have an iterable of things you want to assign to unique values in those columns, charts handles the assignment and cycling your things as needed if you have too many unique values.

The general use case for any chart attribute is this:

  • Explicit input => color=‘Red’ or color=, etc

  • To use the default “things” you just specify the columns, so color=[‘col1’, ‘col2’], or marker=‘col2’ (or both)

  • To customize the default things, the intent is that there will be chart functions that produce this mapping with various input options. So, from bokeh.charts import color, then color=color([‘col1’, ‘col2’], palette=[‘color1’, ‘color2’, ‘color3’]). With this, charts will take the unique values between column 1 and column 2 by name, then will assign color1 to the first, color2 to the second, color3 to the third, color1 to the forth, and so on.

There should be some additional documentation on this topic in the next release in v0.11. For most of your concerns (ticks, grid, border, etc), I’d just handle modifying those on the output Chart object until more of the input options are sorted out. If you can’t get the core attributes working as you want them (color, marker, line color, etc), you can also modify those after creation on the GlyphRenderers and/or their associated ColumnDataSource, but also let us know what difficulties you had so we can work on making it easier.

···

On Sunday, October 25, 2015 at 12:22:10 PM UTC-5, [email protected] wrote:

Is it possible to style Bokeh charts with the same range of styling options as plots made using the plotting interface?

Specifically, I’d like to change the colors, opacity, number of ticks, grid attributes, border attributes etc. on a chart made using the Bar function.

Any help would be great.

-Nik

Ok, so I eventually figured out how to do what I wanted. What I was missing was that the charts interface (unlike something generated using the plotting interface) doesn’t just have attributes for axes or grids or the like. You have to actually use the select() function in order to pick out what you want.

This makes sense once you get the hang of it (I managed to accomplish what I wanted in about half an hour instead of the hours of fiddling that didn’t get me anywhere last night), but I think this is sort of unintuitive. Please correct me if I’m missing something, but it would make a lot more sense to me to just use chart.xaxis or chat.grid instead of chart.select(type=Grid).grid_line_alpha = 0, for example.

Regarding the more general idea that charts shouldn’t need any modification: perhaps, but if you want this to be the case then you need to offer chart styles or something, because I think it’s unreasonable to assume that your default styling is going to be acceptable for everybody. I get that you can use the lower level plotting interface, however from trying it this afternoon, generating a Bar chart using the plotting interface is HARD. Perhaps that’s just a particularly hairy example though, because I was able to do the same for a line graph relatively easily.

···

On Mon, Oct 26, 2015 at 8:20 AM Nick Roth [email protected] wrote:

A lot of the intention of charts is that for most cases you shouldn’t have to worry so much about all the styling details. If you want absolute control over application of colors, etc, then I’d suggest using the lower level interface.

Two things are important to note:

First, that charts produces is a Chart, which subclasses Plot. So, in the end you have the same result, a plot with GlyphRenderers. There will likely be some internal refactoring here soon so that the output provides the maximum flexibility and compatibility possible. So, once you get the output, you can manipulate the plot however you’d like.

Second, the approach with the new charts is to automatically handle the “mapping” of a palette (or anything really) to unique values in one or more columns (df[[‘col1’, ‘col2’]].drop_duplicates()). So, if you have an iterable of things you want to assign to unique values in those columns, charts handles the assignment and cycling your things as needed if you have too many unique values.

The general use case for any chart attribute is this:

  • Explicit input => color=‘Red’ or color=, etc
  • To use the default “things” you just specify the columns, so color=[‘col1’, ‘col2’], or marker=‘col2’ (or both)
  • To customize the default things, the intent is that there will be chart functions that produce this mapping with various input options. So, from bokeh.charts import color, then color=color([‘col1’, ‘col2’], palette=[‘color1’, ‘color2’, ‘color3’]). With this, charts will take the unique values between column 1 and column 2 by name, then will assign color1 to the first, color2 to the second, color3 to the third, color1 to the forth, and so on.

There should be some additional documentation on this topic in the next release in v0.11. For most of your concerns (ticks, grid, border, etc), I’d just handle modifying those on the output Chart object until more of the input options are sorted out. If you can’t get the core attributes working as you want them (color, marker, line color, etc), you can also modify those after creation on the GlyphRenderers and/or their associated ColumnDataSource, but also let us know what difficulties you had so we can work on making it easier.

On Sunday, October 25, 2015 at 12:22:10 PM UTC-5, [email protected] wrote:

Is it possible to style Bokeh charts with the same range of styling options as plots made using the plotting interface?

Specifically, I’d like to change the colors, opacity, number of ticks, grid attributes, border attributes etc. on a chart made using the Bar function.

Any help would be great.

-Nik