[英]Change Color of Non-selected Bokeh Lines
I am starting to use Bokeh to plot data that does not share a common x or y variable.我开始使用 Bokeh 绘制不共享公共 x 或 y 变量的数据。 I would like to be able to select a line and have the other, non-selected lines, grey out.
我希望能够选择一条线并让其他未选择的线变灰。 Ideally the selected line would also be brought to the front of the plot.
理想情况下,选定的线也将被带到情节的前面。
So far I been able to get the line selected, but I can't find a way of "greying out" the non-selected lines, or setting the level of the selected line.到目前为止,我已经能够选择该行,但是我找不到一种方法可以将未选择的行“变灰”或设置所选行的级别。
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)
I'm in a similar situation, and found this example:我处于类似的情况,并找到了这个例子:
https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs
Haven't tried it out myself, but seems to be close to what you're looking for.我自己没有尝试过,但似乎与您要寻找的很接近。
EDIT Just tried it, worked flawlessly for me.编辑刚刚尝试过,对我来说完美无缺。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.