非选中的Bokeh线条如何改变颜色

3

我开始使用Bokeh绘制没有共同的x或y变量的数据。 我希望能够选择一条线,并使其他未选中的线变灰。 理想情况下,所选线也会被带到图的前面。

到目前为止,我已经能够选择线,但我找不到“灰掉”非选定线或设置所选线的级别的方法。

import numpy as np
from bokeh.plotting import figure, show, output_file
from bokeh.models.sources import ColumnDataSource
from bokeh.models import Line,TapTool

output_file("test.html")

x0s = np.random.randint(0,20,20)
y0s = np.random.randint(0,20,20)
x1s = np.random.randint(0,20,20)
y1s = np.random.randint(0,20,20)

p_left = figure(tools=[TapTool()])

for xs,ys in zip([x0s,x1s],[y0s,y1s]):
    source = ColumnDataSource({'x': xs, 'y': ys})
    default_line = Line(x='x', y='y', line_color='blue', line_width=2)
    selected_line = Line(line_color='red', line_width=4)
    nonselected_line = Line(line_color='grey')
    p_left.add_glyph(source,default_line,selection_glyph=selected_line,nonselection_glyph=nonselected_line)

show(p_left)

这里的逻辑问题,我相信,是当你单独绘制物体时,它们不被视为任何可能不被选择的物体集合的一部分。在文档中,他们使用一个命令创建了一组圆圈,然后有些圆圈被选择或未选择是有意义的。我不确定你是否可以将单个物体(也就是你正在创建的)置于非选择状态。我认为唯一的方法是使用multi_line来创建一组线条,这样才能有非选择状态的线条。如果其他人有解决方案使单个物体处于非选择状态,我愿意倾听! - AirSquid
1个回答

3

你能展示一些脚本吗?我正在尝试同样的事情,但它总是选择所有行或所有未选择的行 - 我无法只选择其中的一行。 - jf328

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接