散景颜色未出现在悬停工具提示上

Bokeh color not appearing on hover tooltip

我正在尝试使用 Bokeh 和 运行 解决 hovertool 的一个令人沮丧的问题。它将填充颜色列为涵盖的基本工具提示之一。

http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#hover-tool

我试了一下,hovertool上不会出现颜色。它甚至没有给我“???”当你给它一个它不理解的输入时,它通常会这样做,它只是完全忽略它。任何人都知道为什么它不显示基本工具提示之一?

from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.models import HoverTool

output_file("toolbar.html")

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=[
            ("fill color", "$color[hex, swatch]:fill_color"),
            ("index", "$index"),
            ("(x,y)", "($x, $y)"),
            ("desc", "@desc"),            
        ]
    )

p = figure(plot_width=400, plot_height=400, tools=[hover],
           title="Mouse over the dots")


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

show(p)

悬停工具提示只能检查来自列数据源中实际列 的值。由于您给出了一个固定值,即 fill_color="black" 没有要检查的列。此外,带有 hex 的特殊悬停字段 $color 只能理解十六进制颜色字符串。

这是您修改后可以正常工作的代码:

from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.models import HoverTool

output_file("toolbar.html")

source = ColumnDataSource(
        data=dict(
            x=[1, 2, 3, 4, 5],
            y=[2, 5, 8, 2, 7],
            desc=['A', 'b', 'C', 'd', 'E'],
            fill_color=['#88ffaa', '#aa88ff', '#ff88aa', '#2288aa', '#6688aa']
        )
    )

hover = HoverTool(
        tooltips=[
            ("index", "$index"),
            ("fill color", "$color[hex, swatch]:fill_color"),
            ("(x,y)", "($x, $y)"),
            ("desc", "@desc"),
        ]
    )

p = figure(plot_width=400, plot_height=400, tools=[hover],
           title="Mouse over the dots")


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

show(p)