1

I am currently using this example to create bar chart with Bokeh: http://docs.bokeh.org/en/0.11.0/docs/gallery/stacked_bar_chart.html

Everything works so far, however I couldn't find a way to add data value to each bar like this chart: http://docs.bokeh.org/en/latest/docs/gallery/elements.html

The Bokeh.Charts.Bar class does not have the .text() function like Bokeh.Plotting.Figure. Is there anyway for me to add in the data like the elements chart to the bar chart? I have tried digging around all the codes below the classes and could not find any solution. Help is really appreciated. Thanks in advance.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
Leo
  • 265
  • 1
  • 4
  • 18

1 Answers1

3

A few comments:

First, in the near future (possibly in 0.12 but not certainly) the Chart class will be made a subclass of Figure so that all of the "glyph methods" like Figure.text will also work on charts as well.

Regardless of that, Chart is always a subclass of Plot which means that you can use "low level" glyph objects and Plot.add_glyph anytime. This looks basically like:

from bokeh.models.glyphs import  Text

text_glyph = Text(x="x", y="y", x_offset=10, text="foo")
text_renderer = plot.add_glyph(data_source, text_glyph)

A complete example (from version 0.11.1) using the Text glyph can be seen here.

Finally, just today a new PR was merged to add a proper Label annotation to Bokeh, that will make this kind of thing even easier. You can see the PR here:

https://github.com/bokeh/bokeh/pull/4106

This work will be part of the 0.12 release.

bigreddot
  • 33,642
  • 5
  • 69
  • 122