首页 > 解决方案 > Python Bokeh 悬停工具给出:AttributeError:意外属性“工具提示”到图

问题描述

如何在 Bokeh 0.12.11(可能还有其他版本)中为悬停工具实现“工具提示”?

搜索“散景悬停工具提示”会得到一堆文档结果,例如: https ://docs.bokeh.org/en/latest/docs/user_guide/tools.html

但是,当我尝试通过以下示例在 Bokeh 0.12.11 上实现“工具提示”时: https ://docs.bokeh.org/en/latest/docs/gallery/elements.html

我收到以下错误: AttributeError: unexpected attribute 'tooltips' to Figure, possible attributes are above, aspect_scale, etc.

标签: pythonbokeh

解决方案


解决方案:

我删除了 TOOLTIP= [] 声明,以及 figure() 对象中的 tooltips= 参数。

以编程方式制作悬停工具并附加到图:

from bokeh.models import HoverTool

{ some code }

p = figure(tools=TOOLS, title=TITLE, x_axis_label='Pressure (mTorr)', y_axis_label='Roughness (nm)')

hover = HoverTool()

hover.tooltips = [
    ("Sample", "@names"),
    ("Pressure", "@x_values mTorr"),
    ("Roughness", "@y_values nm"),
]

p.tools.append(hover)

正如这里所指出的: Python Bokeh HoverTool formatters error: "unexpected attribute 'formatters' to HoverTool"

0.12.11 版支持它,但我在实现它时遇到了麻烦。

感谢 bigreddot 指出传递该参数仅适用于 0.13。


推荐阅读