散景悬停工具适用于一个系列,但不适用于组合系列

Bokeh hover tool works on one serie but not in combined series

我对 Bokeh 0.10.0 有疑问。我需要绘制两个系列的矩形(比如说一个红色系列和一个蓝色系列),并在它们上面显示工具提示。我想一个数字会更容易理解:

我不知道如何在所有矩形上显示工具提示。以下最小示例(jupyter notebook)仅显示红色系列的工具提示:

    import bokeh
    from bokeh.charts import show, output_notebook
    from bokeh.models import HoverTool
    from bokeh.plotting import figure, ColumnDataSource
    from collections import OrderedDict
    from bokeh.plotting import figure, output_file, show

    print('bokeh version: %s' %  bokeh.__version__)  # 0.10.0

    plot = figure(width=300, height=300, tools="hover, save")

    x_axis = [1, 2, 3]
    # length of rectangles, starting from 0
    max_ = [1, 2, 3]
    min_ = [-0.5, -1, -7]
    # middle of rectangles
    ytop = [e/2. for e in max_]
    ybot = [e/2. for e in min_]

    # first set of data (red upper rectangles)
    source = ColumnDataSource(data=dict(sval=max_,))
    plot.rect(x=x_axis, y=ytop, width=0.8, height=max_, color="red",source=source)
    # second set of data (blue lower rectangles)
    source = ColumnDataSource(data=dict(sval=min_,))
    plot.rect(x=x_axis, y=ybot, width=0.8, height=min_, color="navy", source=source)
    # create hover tooltips
    hover = plot.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('X', '@x'), ('Valeur', '@sval')])
    # show in notebook    
    output_notebook()
    show(plot)

我认为这是因为您指定了负高度,这似乎显示正常,但悬停工具的 hit-testing 显然失败了。

如果您将 min_ 更改为正值(对于 height=)并将 ybot 更改为负值,它对我有用。

例如:

min_ = [abs(x) for x in [-0.5, -1, -2]]
ybot = [-e/2. for e in min_]

如果负高度应该工作,这将是一个错误,如果不允许负高度,它的散景至少应该失败一点更一致并显示一些警告。

我在 Bokeh 0.11.0dev9 上测试过,它的行为似乎与 0.10 类似。

编辑: 如果数据中至少有 1 个正高度,则所有悬停都正确显示,也包括负高度的悬停。所以它似乎只在所有负高度上失败。

我在 Github 上创建了一个问题,请参阅:

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