Python的背景虚化HoverTool格式化错误:
问题描述:
我用jupyter笔记本做可视化的做法“意外属性‘格式化’到HoverTool”,然后我也跟着上http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#basic-tooltipsPython的背景虚化HoverTool格式化错误:
它的工作原理的代码,所以我试图添加“格式化工具提示”,如下面的代码。
我只是添加了属性'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中添加,PR #6183是0.12.6
版本的一部分。您至少需要安装Bokeh 0.12.6
或更新版本才能使用它。
背景虚化还是增加新的功能,所以如果你没有安装最新版本的背景虚化的,它引用文档为你实际已安装的版本,例如是很重要的
http://bokeh.pydata.org/en/0.12.5/
提供文档专门为0.12.5
版本。另外,您始终可以从CDN获取特定于您安装版本的示例代码。再次0.12.5
版本有:
+0
是的,问题是因为旧版本发生的。更新至0.12.6后,问题已修复。谢谢。 – fishballLin
我记得有一个类似的问题一次,问题是,我是按照最新的文档,但使用年龄稍大的背景虚化。先尝试更新您的散景套餐到最新的套餐。 –
好的,让我检查一下。谢谢 – fishballLin
@IgnacioVergaraKausel你是对的。我正在使用较旧的散景0.12.4。更新软件包后,我解决了这个问题。非常感谢你。 – fishballLin