Python Bokeh HoverTool formatters error: “unexpect

2019-07-20 23:09发布

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

the code on the website

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

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)

the error message:

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

1条回答
Summer. ? 凉城
2楼-- · 2019-07-20 23:17

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 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://bokeh.pydata.org/en/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.pydata.org/bokeh/examples/examples-0.12.5.zip

查看更多
登录 后发表回答