Bokeh Hovertool for patch

≡放荡痞女 提交于 2019-12-11 09:46:10

问题


Is the hover tool for patch different than other glyphs? The plot can see the index for circle but not for patch.

output_file("patch.html")

    TOOLTIPS = [
        ("index", "$index"),
    ]
    p = figure(plot_width=400, plot_height=400, tooltips=TOOLTIPS, tools='hover,help')

    # add a patch renderer with an alpha an line width
    p.patch([1, 2, 3, 4, 5], [6, 7, 8, 7, 3], alpha=0.5, line_width=2)
    p.circle([2], [4],size=20, line_width=2)

    show(p)


回答1:


As of Bokeh 1.0.2, hit testing has not been implemented for Patch, i.e. it is invisible as far as the Hover tool is concerned. You could use the vectorized patches glyph method instead:

p.patches([[1, 2, 3, 4, 5]], [[6, 7, 8, 7, 3]], alpha=0.5, line_width=2)

However, this will always only return 0 as the value of $index since there is only just the one patch (whose index is 0). If you are looking to get "index" values for the vertices of the patch, you will need to do something like plot invisible circles at the same locations as the vertices, that are only there for hit-testing purposes (to drive the hover tool)



来源:https://stackoverflow.com/questions/53383908/bokeh-hovertool-for-patch

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