在bokeh vbar工具提示中显示高度 [英] Display height in bokeh vbar tooltip

查看:79
本文介绍了在bokeh vbar工具提示中显示高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一些简单数据的条形图,例如这样的熊猫数据框.

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

使用条形图,可以使用

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

自从我切换到vbars. @height对应的关键字是什么?还是通常不适用于vbars/hbars?

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

推荐答案

我知道了.我可以像这样制作一个额外的ColumnDataSource:

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

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

产生动物值列表.然后可以将其用于vbar,如下所示:

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'),
]

这篇关于在bokeh vbar工具提示中显示高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆