[bokeh] Custom Hover tooltips for Bar Charts

This is happening because names isn’t a column on the data source that’s driving your plot.

The short answer is use @cat.

You can see the data source that’s driving the plot as follows:

glyph_ renderers = bar.select(dict(type=GlyphRenderer))
bar_source = glyph_renderers[0].data_source

bar_source.column_names
or
bar_source.data

Hope that helps.

···

On Wed, Aug 5, 2015 at 5:22 PM, Kevad [email protected] wrote:

Hello,

I have a data in which one column is a list of names. Can I make a custom hover tooltip for bar charts to work ?

    from bokeh.charts import Bar
    from bokeh.models import HoverTool
    numbers = [1, 2, 3, 4, 5]
    names = ['a', 'b', 'c', 'd', 'e']
    bar = Bar(numbers, names, tools='hover')
    hover = bar.select(dict(type=HoverTool))
    hover.tooltips = [
      ('position', '$index'),
      ('name',' @names'),
    ]
    show(bar)

For position, the hover is working fine, but for ‘name’ it shows ‘???’. Any idea how to make it work ? Or am I making something wrong ?

Thanks,

Kevad.

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/fc7723e4-2172-429e-be5e-5f3c3b78af1f%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thanks a lot Sarah. It really helped. :slight_smile:

For others, here is the full working version:

    from bokeh.charts import Bar

    from bokeh.models import HoverTool

    from bokeh.models.renderers import GlyphRenderer

    numbers = [1, 2, 3, 4, 5]

    names = ['a', 'b', 'c', 'd', 'e']

    bar = Bar(numbers, names, tools='hover')

    glyph_renderers = bar.select(dict(type=GlyphRenderer))

    bar_source = glyph_renderers[0].data_source

    hover = bar.select(dict(type=HoverTool))

    hover.tooltips = [

      ('position', '$index'),

      ('name',' @cat'),

      ('number', '@zero'),  

    ]

    show(bar)
  • Kevad.
···

On Wednesday, August 5, 2015 at 6:19:27 PM UTC+2, Sarah Bird wrote:

This is happening because names isn’t a column on the data source that’s driving your plot.

The short answer is use @cat.

You can see the data source that’s driving the plot as follows:

glyph_ renderers = bar.select(dict(type=GlyphRenderer))
bar_source = glyph_renderers[0].data_source

bar_source.column_names
or
bar_source.data

Hope that helps.

On Wed, Aug 5, 2015 at 5:22 PM, Kevad [email protected] wrote:

Hello,

I have a data in which one column is a list of names. Can I make a custom hover tooltip for bar charts to work ?

    from bokeh.charts import Bar
    from bokeh.models import HoverTool
    numbers = [1, 2, 3, 4, 5]
    names = ['a', 'b', 'c', 'd', 'e']
    bar = Bar(numbers, names, tools='hover')
    hover = bar.select(dict(type=HoverTool))
    hover.tooltips = [
      ('position', '$index'),
      ('name',' @names'),
    ]
    show(bar)

For position, the hover is working fine, but for ‘name’ it shows ‘???’. Any idea how to make it work ? Or am I making something wrong ?

Thanks,

Kevad.

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/fc7723e4-2172-429e-be5e-5f3c3b78af1f%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Sarah, I can’t seem to get this code working with bokeh 0.11 python 3.5. Error: ‘NoneType’ object is not iterable. What happened w.r.t. the prev. bokeh versions?
(I have this issue with a lot of code I find on the internet on Bokeh plots, just copy pasting it and an error occurs

I’m looking forward to your response.

Rakesh

···

On Wednesday, August 5, 2015 at 6:19:27 PM UTC+2, Sarah Bird wrote:

This is happening because names isn’t a column on the data source that’s driving your plot.

The short answer is use @cat.

You can see the data source that’s driving the plot as follows:

glyph_ renderers = bar.select(dict(type=GlyphRenderer))
bar_source = glyph_renderers[0].data_source

bar_source.column_names
or
bar_source.data

Hope that helps.

On Wed, Aug 5, 2015 at 5:22 PM, Kevad [email protected] wrote:

Hello,

I have a data in which one column is a list of names. Can I make a custom hover tooltip for bar charts to work ?

    from bokeh.charts import Bar
    from bokeh.models import HoverTool
    numbers = [1, 2, 3, 4, 5]
    names = ['a', 'b', 'c', 'd', 'e']
    bar = Bar(numbers, names, tools='hover')
    hover = bar.select(dict(type=HoverTool))
    hover.tooltips = [
      ('position', '$index'),
      ('name',' @names'),
    ]
    show(bar)

For position, the hover is working fine, but for ‘name’ it shows ‘???’. Any idea how to make it work ? Or am I making something wrong ?

Thanks,

Kevad.

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/fc7723e4-2172-429e-be5e-5f3c3b78af1f%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Rakesh,

Bokeh is a large project, with different parts that have different levels of stability and maturity. Getting things right sometimes means experimenting and seeing what works for a time, which sometimes means breaking APIs. We try to minimize this, of course, because it can understandably be frustrating, but sometimes it is unavoidable if forward progress is to continue. This has been particularly true of the bokeh.charts interface, which is the newest and least mature API. The bokeh.charts API has started to stabilize much more redently, but the internet remembers everything, including old and outdated things that are no longer relevant. My recommendation is to use the official docs (for the version of Bokeh you are using) and the mailing list as much as possible, especially with bokeh.charts questions.

Thanks,

Bryan

···

On Mar 18, 2016, at 4:51 AM, [email protected] wrote:

Hi Sarah, I can't seem to get this code working with bokeh 0.11 python 3.5. Error: 'NoneType' object is not iterable. What happened w.r.t. the prev. bokeh versions?
(I have this issue with a lot of code I find on the internet on Bokeh plots, just copy pasting it and an error occurs

I'm looking forward to your response.

Rakesh

On Wednesday, August 5, 2015 at 6:19:27 PM UTC+2, Sarah Bird wrote:
This is happening because names isn't a column on the data source that's driving your plot.

The short answer is use @cat.

You can see the data source that's driving the plot as follows:

glyph_ renderers = bar.select(dict(type=GlyphRenderer))
bar_source = glyph_renderers[0].data_source

bar_source.column_names
or
bar_source.data

Hope that helps.

On Wed, Aug 5, 2015 at 5:22 PM, Kevad <[email protected]> wrote:
Hello,

  I have a data in which one column is a list of names. Can I make a custom hover tooltip for bar charts to work ?

        from bokeh.charts import Bar
        from bokeh.models import HoverTool

        numbers = [1, 2, 3, 4, 5]
        names = ['a', 'b', 'c', 'd', 'e']

        bar = Bar(numbers, names, tools='hover')
        hover = bar.select(dict(type=HoverTool))

        hover.tooltips = [
          ('position', '$index'),
          ('name',' @names'),
        ]

        show(bar)

  For position, the hover is working fine, but for 'name' it shows '???'. Any idea how to make it work ? Or am I making something wrong ?

Thanks,
Kevad.

--
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 bokeh+un...@continuum.io.
To post to this group, send email to bo...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/fc7723e4-2172-429e-be5e-5f3c3b78af1f%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
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/d11b0b07-ac08-41ec-af01-671bf0b2f61a%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
<bokehError.png>