我开始使用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