Bokeh,multi_line:如何使用选择框选择几行?

问题描述 投票:0回答:1

我有一个用多行字形创建的散景图。我可以使用点击工具选择单行,或者使用TapTool + Shift选择多行。有没有一种方法可以使用BoxSelectTool选择几行(如图所示)?沿每条线的点的密度很高,因此,仅当线的1个以上点位于框选择区域内时,选择才有效。我正在寻找没有Python服务器的独立解决方案。编写一些CustomJS代码是可以的。

from bokeh.models import ColumnDataSource
from bokeh.layouts import column
import numpy as np

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

f1 = figure(plot_width=800, plot_height=300, tools='tap,box_select,reset')
f2 = figure(plot_width=800, plot_height=300)
f1.multi_line(xs='xx', ys='yy', source=data)
f2.multi_line(xs='xx', ys='zz', source=data)

save(column(f1, f2))

Plot sample with the box selection

谢谢。

python bokeh selection
1个回答
0
投票

此功能不是内置的,至少不是在Bokeh 2.0.2中。 MultiLine字形仅定义_hit_point(由点击,悬停和编辑工具使用)和_hit_span(由悬停工具使用)方法。为了使选择框工作,需要定义一个_hit_rect方法。自己做起来并不难,但是您将不得不创建一个自定义的Bokeh模型并为其编写一些TypeScript。

话虽如此,请随时在Bokeh的GitHub上创建功能请求!

© www.soinside.com 2019 - 2024. All rights reserved.