我正在尝试使用Bokeh并遇到令人沮丧的问题。它将填充颜色列为所涵盖的基本工具提示之一。
http://bokeh.pydata.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)
答案 0 :(得分:1)
悬停工具提示只能检查列数据源中实际列的值。由于您已经给出了固定值,即fill_color="black"
,因此没有要检查的列。此外,带$color
的特殊悬停字段hex
只能理解十六进制颜色字符串。
以下是您修改后的代码:
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)