小编Fra*_*eis的帖子

获取Bokeh中框选择工具中包含的选定数据

如果我在散景中有一个散点图并且我启用了Box Select Tool,假设我使用Box Select Tool选择了几个点.如何访问我选择的点的(x,y)位置信息?

%matplotlib inline
import numpy as np
from random import choice
from string import ascii_lowercase

from bokeh.models.tools import *
from bokeh.plotting import *

output_notebook()


TOOLS="pan,wheel_zoom,reset,hover,poly_select,box_select"
p = figure(title = "My chart", tools=TOOLS)
p.xaxis.axis_label = 'X'
p.yaxis.axis_label = 'Y'

source = ColumnDataSource(
    data=dict(
        xvals=list(range(0, 10)),
        yvals=list(np.random.normal(0, 1, 10)),
        letters = [choice(ascii_lowercase) for _ in range(10)]
    )
)
p.scatter("xvals", "yvals",source=source,fill_alpha=0.2, size=5)

select_tool = p.select(dict(type=BoxSelectTool))[0]

show(p)

# How can I know which points are contained in the Box Select …
Run Code Online (Sandbox Code Playgroud)

python bokeh

7
推荐指数
2
解决办法
3397
查看次数

标签 统计

bokeh ×1

python ×1