[英]Bokeh color not appearing on hover tooltip
I'm experimenting with Bokeh and running into a frustrating problem with the hovertool.我正在尝试 Bokeh 并遇到了一个令人沮丧的悬停工具问题。 It lists fill color as one of the basic tooltips covered.它将填充颜色列为涵盖的基本工具提示之一。
http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#hover-tool http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#hover-tool
I tried a test and the color will not appear on the hovertool.我尝试了一个测试,颜色不会出现在悬停工具上。 It doesn't even give me the "???"它甚至没有给我“???” it usually does when you give it a input it doesn't understand, it just ignores it completely.当你给它一个它不理解的输入时,它通常会这样做,它只是完全忽略它。 Anyone have a clue as to why it wouldn't display one of the basic tooltips?任何人都知道为什么它不显示基本工具提示之一?
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)
Hover tooltips can only inspect values from actual columns in a column data source.悬停工具提示只能检查列数据源中实际列的值。 Since you have given a fixed value, ie fill_color="black"
there is no column to inspect.由于您给出了一个固定值,即fill_color="black"
没有要检查的列。 Additionally, the special hover field $color
with hex
only understands hex color strings.此外,带有hex
的特殊悬停字段$color
仅理解十六进制颜色字符串。
Here is your code modified to work:这是您修改后的代码:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.