散景:如何使 CDSView 正确处理矢量化颜色?

Bokeh: how to make CDSView work with vectorized colors correctly?

我绝对不是第一个问这个问题的人,但之前的问题都是零答案。

我正在使用带有矢量化着色的 Bokeh MultiLine 字形。如果未指定 CSD 视图(下图),一切都很好,并且选择响应是正确的。但是顶部图形上的相同字形会在选择时改变颜色。此外,如果上图有CDSView,则点击选择对下图不起作用。

据我所知人们报告了其他字形类型的类似行为。

是否有解决此问题的方法?我错过了一些重要的 CDSView 参数吗? 谢谢!

from bokeh.plotting import figure, output_file, save
from bokeh.models import ColumnDataSource, BooleanFilter, CDSView
from bokeh.layouts import column, gridplot
from bokeh.palettes import d3
import numpy as np

output_file('tst.html', mode="inline")
n = 4
t = np.linspace(0., 10., 80)
data = ColumnDataSource(dict(xx=[t for cnt in range(n)],
                             yy=[(10 + cnt/2)*np.sin(t) + 5*cnt*(-1)**cnt for cnt in range(n)],                             
                             clrs=d3['Category10'][4]))

test_filter = BooleanFilter([False, True, True, True])

view0 = CDSView(source=data, filters=[test_filter])
f1 = figure(plot_width=300, plot_height=300, tools='tap,box_select,reset')
f2 = figure(plot_width=300, plot_height=300)
f1.multi_line(xs='xx', ys='yy', source=data, color="clrs",
              view=view0,
              nonselection_alpha=0.4)

f2.multi_line(xs='xx', ys='yy', source=data, color="clrs",
              nonselection_alpha=0.4)
save(gridplot([[f1], [f2]]))

Behavior on selection

从 Bokeh 2.0.2 开始,它仍然是一个悬而未决的问题:https://github.com/bokeh/bokeh/issues/9230#issuecomment-631291583

还相关:https://github.com/bokeh/bokeh/issues/8010