Display height in bokeh vbar tooltip

与世无争的帅哥 提交于 2019-12-23 20:33:07

问题


I want to make a bar chart of some simple data, e.g. a pandas dataframe like this.

Cats 4
Dogs 3
Mice 27

I would like a tooltip which displays something like this when hovering over a bar:

Name: Cats
Count: 4

With a bar chart, this worked with

hover.tooltips = [
('Name', ' $x'),
('Count', ' @height'),
]

I since switched to vbars. What would be the corresponding keyword for @height? Or does it generally not work this way with vbars/hbars?


回答1:


I figured it out. I could make an extra ColumnDataSource like this:

hover_help = ColumnDataSource(dict(
    count=[value for value in animals["No"]]
))

which yields a list of values for animals. This can then be used for the vbar like this:

p.vbar(source=hover_help, bottom=0, x=animal_names, top=animals['No'], color='#18286b', legend=False, **bar_opts)

Even if the source is not used as a data source, it can now be used for the tooltip:

hover.tooltips = [
    ('Name', ' $x'),
    ('Count', ' @count'),
]


来源:https://stackoverflow.com/questions/42402718/display-height-in-bokeh-vbar-tooltip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!