1
Bokeh 플롯에서 선택한 데이터 포인트를 쓰려고합니다. Button
을 클릭 할 때마다 ColumnDataSource
selected
속성에 액세스하여 선택한 데이터 요소를 가져 오는 것이 좋습니다.Bokeh 플롯 선택한 데이터가 작동하지 않습니다.
다음은 달성하려는 기능의 모델입니다.
기대하십시오 '선택한 점'버튼을 클릭 한 후, 파일 /tmp/datapoints.json
선택 점의 목록 (있는 경우)를 포함하는 생성 될 것이다.
실재 : 아니요 /tmp/datapoints.json
.
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.io import show
from bokeh.models import ColumnDataSource, Button
from bokeh.layouts import column
# setup plot
fig = figure(title='Select points',
plot_width=300, plot_height=200)
import numpy as np
x = np.linspace(0,10,100)
y = np.random.random(100) + x
import pandas as pd
data = pd.DataFrame(dict(x=x, y=y))
# define data source
src = ColumnDataSource(data)
# define plot
fig.circle(x='x', y='y', source=src)
# define interaction
def print_datapoints(attr, old, new):
with open('/tmp/datapoints.json', 'w') as f:
import json
json.dump(src.selected, f)
btn = Button(label='Selected points', button_type='success')
btn.on_click(print_datapoints)
curdoc().add_root(column(btn,fig))
무엇이 누락 되었습니까?
감사합니다. lasso_select 도구
감사합니다. @ 요리스. 나는 내가 선택 도구 (들)을 놓치고있는 것을 보았다! – Brandt