Python Bokeh HoverTool格式化程序错误:"HoverTool的意外属性'formatters'" [英] Python Bokeh HoverTool formatters error: "unexpected attribute 'formatters' to HoverTool"

查看:94
本文介绍了Python Bokeh HoverTool格式化程序错误:"HoverTool的意外属性'formatters'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jupyter笔记本进行可视化练习,然后按照

I used jupyter notebook to do a practice of visualization, then I followed the code on http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#basic-tooltips

网站上的代码

它有效,因此我尝试添加格式设置工具提示",如下面的代码.

It works, so I tried to add the "Formatting Tooltip", like the below code.

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

I just only added the attribute 'formatters', but the error happened.

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或更高版本才能使用它.

The above comment is certainly correct. The .formatters property for HoverTool was only added recently in PR #6183, which was part of the 0.12.6 release. You will need to have at least Bokeh 0.12.6 or newer installed to use it.

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

Bokeh is still adding new features, so if you do not have the latest version of Bokeh installed, it is important to reference the docs for the version you actually have installed, e.g.

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

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

Provides docs specifically for version 0.12.5. Additionally you can always obtain the example code specific to your installed version from CDN. Again for version 0.12.5 there is:

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

这篇关于Python Bokeh HoverTool格式化程序错误:"HoverTool的意外属性'formatters'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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