2017-08-24 94 views
1

我用jupyter筆記本做可視化的做法「意外屬性‘格式化’到HoverTool」,然後我也跟着上http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#basic-tooltipsPython的背景虛化HoverTool格式化錯誤:

the code on the website

它的工作原理的代碼,所以我試圖添加「格式化工具提示」,如下面的代碼。

我只是添加了屬性'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 
+0

我記得有一個類似的問題一次,問題是,我是按照最新的文檔,但使用年齡稍大的背景虛化。先嚐試更新您的散景套餐到最新的套餐。 –

+0

好的,讓我檢查一下。謝謝 – fishballLin

+0

@IgnacioVergaraKausel你是對的。我正在使用較舊的散景0.12.4。更新軟件包後,我解決了這個問題。非常感謝你。 – fishballLin

回答

1

上述評論當然是正確的。 HoverTool.formatters屬性最近僅在PR #6183中添加,PR #61830.12.6版本的一部分。您至少需要安裝Bokeh 0.12.6或更新版本才能使用它。


背景虛化還是增加新的功能,所以如果你沒有安裝最新版本的背景虛化的,它引用文檔爲你實際已安裝的版本,例如是很重要的

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

提供文檔專門爲0.12.5版本。另外,您始終可以從CDN獲取特定於您安裝版本的示例代碼。再次0.12.5版本有:

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

+0

是的,問題是因爲舊版本發生的。更新至0.12.6後,問題已修復。謝謝。 – fishballLin