Python Bokeh HoverTool formatters error: “unexpected attribute 'formatters' to HoverTool”

有些话、适合烂在心里 提交于 2019-12-11 02:59:47

问题


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

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:


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



来源:https://stackoverflow.com/questions/45855928/python-bokeh-hovertool-formatters-error-unexpected-attribute-formatters-to-h

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