bokeh hovertool如何为相同坐标的多条线段显示多个工具提示条目

2024-04-28 23:04:33 发布

您现在位置:Python中文网/ 问答频道 /正文

当多个相同大小的对象在图表上处于同一位置时,尽管只有“堆栈”的顶部可见,但我希望在工具提示框中看到所有这些对象的描述。你知道吗

  • 这是使用圆图时的行为,例如:
    from bokeh.plotting import figure, output_notebook, show, ColumnDataSource
    output_notebook()

    source = ColumnDataSource(data=dict(
        x=[1, 2, 2, 4, 5],
        y=[2, 5, 5, 2, 7],
        desc=['A', 'b', 'C', 'd', 'E'],
    ))

    TOOLTIPS = [
        ("index", "$index"),
        ("desc", "@desc"),
    ]

    p = figure(plot_width=400, plot_height=400, tooltips=TOOLTIPS,
               title="Mouse over the dots")

    p.circle('x', 'y', size=20, source=source)

    show(p)

enter image description here

  • 但是,在下面使用多行打印的示例中,工具提示框中仅显示一条记录,尽管两条线段具有完全相同的坐标
    from bokeh.plotting import figure, output_notebook, show, ColumnDataSource
    output_notebook()

    source = ColumnDataSource(data=dict(
        x=[(1, 2), (2, 3), (4, 5), (2, 3)],
        y=[(2, 5), (5, 4), (2, 7), (5, 4)],
        desc=['A', 'b', 'C', 'D'],
    ))

    TOOLTIPS = [
        ("index", "$index"),
        ("desc", "@desc"),
    ]

    p = figure(plot_width=400, plot_height=400, tooltips=TOOLTIPS,
               title="Mouse over the dots")

    p.multi_line(xs='x', ys='y', line_width=4, source=source)

    show(p)

enter image description here

如何获得工具提示以显示多行的多个条目?


Tags: 工具对象fromsourceoutputindexplotshow
1条回答
网友
1楼 · 发布于 2024-04-28 23:04:33

这是不可能的,但是你可以同时做到:p.multi_line(...)p.circle(...)(按这个顺序)。如果你想,你可以使圆足够小(例如size = 5),所以他们是不可见的。然后可以将这些圆指定为悬停的唯一渲染器,如下所示:

circles = p.circle(...)
p.hover.renderers = [circles]

相关问题 更多 >