Python Bokeh HoverTool formatters error: "unexpected attribute 'formatters' to HoverTool"

Python Bokeh HoverTool formatters error: "unexpected attribute 'formatters' to HoverTool"

我用jupyter notebook做了一个可视化练习,然后我按照http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#basic-tooltips

上的代码

the code on the website

有效,所以我尝试添加 "Formatting Tooltip",如下面的代码。

我刚刚只添加了属性'formatters',但是错误发生了。

from bokeh.plotting import figure, ColumnDataSource
from bokeh.models import HoverTool
from bokeh.io import output_notebook, show

output_notebook()

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    desc=['A', 'b', 'C', 'd', 'E'],
))

hover = HoverTool(
        tooltips=[
            ("index", "$index"),
            ("(x,y)", "($x, $y)"),
            ("desc", "@desc"),
        ],
        formatters={
            'desc' : 'printf', # use 'datetime' formatter for 'date' field
                               # use default 'numeral' formatter for other fields
        }
    )

p = figure(plot_width=400, plot_height=400, tools=[hover],
           title="Mouse over the dots")

p.circle('x', 'y', size=20, source=source)

错误信息:

AttributeError: unexpected attribute 'formatters' to HoverTool, possible attributes are anchor, attachment, callback, js_callbacks, line_policy, mode, name, names, plot, point_policy, renderers, show_arrow, tags or tooltips

以上评论当然是正确的。 HoverTool.formatters 属性 最近才添加到 PR #6183 中,它是 0.12.6 版本的一部分。您至少需要安装 Bokeh 0.12.6 或更新版本才能使用它。


Bokeh 仍在添加新功能,因此如果您没有安装最新版本的 Bokeh,请务必参考您实际安装的版本的文档,例如

http://docs.bokeh.org/en/0.12.5/

提供专门针对版本 0.12.5 的文档。此外,您始终可以从 CDN 获取特定于您安装的版本的示例代码。同样对于版本 0.12.5 有:

https://cdn.bokeh.org/bokeh/examples/examples-0.12.5.zip