Python Bokeh Hover Tool giving: AttributeError: unexpected attribute 'tooltips' to Figure

那年仲夏 提交于 2019-12-12 00:51:55

问题


How do I implement "tooltips" for the hover tool in Bokeh 0.12.11 (and possibly other versions)?

Searching for "Bokeh hover tooltips" gives a bunch of documentation results such as: https://docs.bokeh.org/en/latest/docs/user_guide/tools.html

But when I try to implement the "tooltips" on Bokeh 0.12.11 from an example such as: https://docs.bokeh.org/en/latest/docs/gallery/elements.html

I get the following error: AttributeError: unexpected attribute 'tooltips' to Figure, possible attributes are above, aspect_scale, etc.


回答1:


Solution:

I removed the TOOLTIP= [] declaration, and the tooltips= parameter in the figure() object.

Make the Hover Tool programatically and attach to Figure:

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)

As pointed out here: Python Bokeh HoverTool formatters error: "unexpected attribute 'formatters' to HoverTool"

version 0.12.11 supports it but I was having trouble implementing it.

Thanks to bigreddot for pointing out that passing that parameter only works in 0.13.



来源:https://stackoverflow.com/questions/51413483/python-bokeh-hover-tool-giving-attributeerror-unexpected-attribute-tooltips

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