【问题标题】:Bokeh, multi_line: how to select several lines with the box select?Bokeh,multi_line:如何用框选择选择几行?
【发布时间】:2020-05-11 04:26:27
【问题描述】:

我有一个使用多线字形创建的散景图。我可以使用点击工具选择单行或使用 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】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多