2

我的问题是,在 Chrome 中,当我的直方图上的光标悬停在我的数据上时,我有这个错误:

Uncaught TypeError: Cannot read property '0'

有我的代码:

hist, edges = np.histogram(data,bins=3000)

plot = quad(
    top=hist,
    bottom=0,
    left=edges[:-1],
    right=edges[1:],
    fill_color="#036564",
    line_color="#033649",
    tools="pan,wheel_zoom,box_zoom,reset, hover",
    x_range=[-0.5,3.5],
    plot_width=1100, 
    title="",
)

hover = plot.select(dict(type=HoverTool))
hover.tooltips = [('index','$index')]

resources = Resources("inline")

plot_script, plot_div = components(plot, resources)

html_script = mark_safe(encode_utf8(plot_script))
html_div = mark_safe(encode_utf8(plot_div))

figure()

return html_script, html_div

“数据”是一个像这样的数组:

[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1.24,1,1.32,1,2,3]

我试图在四边形中添加一个“源”,更改了图形,更改了文档中的代码,但我仍然有错误。

有关信息,除了悬停工具外,一切都运行良好。

事实上,在“悬停框”中,我想要另一个信息,然后只是“索引”,但这只是为了测试。

谢谢阅读 !

4

1 回答 1

0

抱歉,我之前错过了这个。您发现了quad字形特有的悬停工具的一个小错误。同时,您可以添加hover.snap_to_data = False以使其正常工作。

这是您可以跟踪的完整解决方案的 GH 问题:

https://github.com/bokeh/bokeh/issues/1644

下周一应该会在 0.7.1 版本中进行修复。

另外顺便说一句,您正在使用已弃用的 API。您现在应该编写如下代码:

p = figure(...)
p.quad(...)
于 2015-01-07T23:21:09.150 回答