如何在 Bokeh 的 HoverTool 工具提示中显示与系列关联的图例名称?
How do I display the legend name associated with a series in the HoverTool tooltip in Bokeh?
在下面的代码中,我想知道用什么来代替“????”这样悬停工具将显示系列的名称(在本例中为 "series 1" 或 "series 2")
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import HoverTool, ColumnDataSource
output_notebook()
hover = HoverTool()
hover.tooltips=[("series name","????")]
f = figure(tools=[hover])
f.line([1,2,3],[2,1,5],legend="series 1")
f.line([1,2,3],[1,7,2],legend="series 2")
show(f)
我知道您可以执行以下操作来完成这项工作(请参阅 In Bokeh, how do I add tooltips to a Timeseries chart (hover tool)?)。然而,我将这些图嵌入到一个 HTML 文件中,每个图都有很多数据点,文件中有很多图,所以我有兴趣最小化嵌入 HTML 中的数据源的大小文件。
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import HoverTool, ColumnDataSource
output_notebook()
hover = HoverTool()
hover.tooltips=[("series name","@legend")]
f = figure(tools=[hover])
data1 = ColumnDataSource({"x":[1,2,3], "y":[2,1,5], "legend":["series 1"]*3})
data2 = ColumnDataSource({"x":[1,2,3], "y":[1,7,2], "legend":["series 2"]*3})
f.line("x","y",source=data1, legend="series 1")
f.line("x","y",source=data2, legend="series 2")
show(f)
如果我理解正确的话,只有将特定的工具提示与特定的渲染器相关联时,您想要做的事情才有效(有效)。在 Github 上,以下评论存在问题,提供了一个小代码片段来执行您想要的操作:https://github.com/bokeh/bokeh/issues/3454#issuecomment-168238796
在下面的代码中,我想知道用什么来代替“????”这样悬停工具将显示系列的名称(在本例中为 "series 1" 或 "series 2")
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import HoverTool, ColumnDataSource
output_notebook()
hover = HoverTool()
hover.tooltips=[("series name","????")]
f = figure(tools=[hover])
f.line([1,2,3],[2,1,5],legend="series 1")
f.line([1,2,3],[1,7,2],legend="series 2")
show(f)
我知道您可以执行以下操作来完成这项工作(请参阅 In Bokeh, how do I add tooltips to a Timeseries chart (hover tool)?)。然而,我将这些图嵌入到一个 HTML 文件中,每个图都有很多数据点,文件中有很多图,所以我有兴趣最小化嵌入 HTML 中的数据源的大小文件。
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import HoverTool, ColumnDataSource
output_notebook()
hover = HoverTool()
hover.tooltips=[("series name","@legend")]
f = figure(tools=[hover])
data1 = ColumnDataSource({"x":[1,2,3], "y":[2,1,5], "legend":["series 1"]*3})
data2 = ColumnDataSource({"x":[1,2,3], "y":[1,7,2], "legend":["series 2"]*3})
f.line("x","y",source=data1, legend="series 1")
f.line("x","y",source=data2, legend="series 2")
show(f)
如果我理解正确的话,只有将特定的工具提示与特定的渲染器相关联时,您想要做的事情才有效(有效)。在 Github 上,以下评论存在问题,提供了一个小代码片段来执行您想要的操作:https://github.com/bokeh/bokeh/issues/3454#issuecomment-168238796