2016-08-01 3 views
2

4 세트의 데이터로 작업하고 있는데, 각각에는 여러 개의 시계열 수가 있습니다. 내가 함께 그들 모두를 플로팅 보케를 사용하고, 그 결과는 다음과 같습니다MultiSelect 위젯을 사용하여 bokeh의 줄을 숨기고 표시합니다.

multiline graph bokeh with widget

from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import RdYlGn4 
from bokeh.models import CustomJS, ColumnDataSource, MultiSelect 
from bokeh.layouts import row, widgetbox 

output_file("graph.html") 
p = figure(plot_width=1000, plot_height=400, x_axis_type="datetime", title="title") 
cadena=range(4) 
for i,comp in enumerate(cadena): 
    ts=[t for t in data_plu_price.columns if int(t) in df.T[df.C==comp].values] 
    n_lines=len(data[ts].columns) 
    p.multi_line(xs=[data[ts].index.values]*n_lines, ys=[data[t].values for t in ts],line_color=RdYlGn4[i], legend=str(i)) 
p.title.align = "center" 
p.title.text_font_size = "20px" 
p.xaxis.axis_label = 'date' 
p.yaxis.axis_label = 'price' 

callback = CustomJS("""Some Code""") 
multi_select = MultiSelect(title="Select:", value=cadena, 
         options=[(str(i), str(i)) for i in range(4)]) 
layout = row(p,widgetbox(multi_select)) 
show(layout) 

문제가 정말 더러워 보이는 것입니다, 그래서 내가 보여주기 위해 다중 선택 위젯을 사용하는 wanned/multilines (4)의 모든 그룹을 숨 깁니다. 어떤 종류의 코드를 multi_line 생성에 사용하고이 상호 작용을 만들기위한 콜백 객체에 사용해야합니까?

어떤 안내?

미리 감사드립니다. (/ 쇼 라인을 숨기기 위해 다중 선택 위젯을 사용하여) 정확하게 작업을 수행하기위한

답변

2

지원 만이 PR에 버전 0.12.1에 추가되었습니다 https://github.com/bokeh/bokeh/pull/4868

여기 예를 들어 있습니다 (아래 복사) : https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/line_on_off.py

""" Example demonstrating turning lines on and off - with JS only 

""" 

import numpy as np 

from bokeh.io import output_file, show 
from bokeh.layouts import row 
from bokeh.palettes import Viridis3 
from bokeh.plotting import figure 
from bokeh.models import CheckboxGroup, CustomJS 

output_file("line_on_off.html", title="line_on_off.py example") 

code = """ 
    if (0 in checkbox.active) { 
     l0.visible = true 
    } else { 
     l0.visible = false 
    } 
    if (1 in checkbox.active) { 
     l1.visible = true 
    } else { 
     l1.visible = false 
    } 
    if (2 in checkbox.active) { 
     l2.visible = true 
    } else { 
     l2.visible = false 
    } 
""" 

p = figure() 
props = dict(line_width=4, line_alpha=0.7) 
x = np.linspace(0, 4 * np.pi, 100) 
l0 = p.line(x, np.sin(x), color=Viridis3[0], legend="Line 0", **props) 
l1 = p.line(x, 4 * np.cos(x), color=Viridis3[1], legend="Line 1", **props) 
l2 = p.line(x, np.tan(x), color=Viridis3[2], legend="Line 2", **props) 

callback = CustomJS(code=code, args={}) 
checkbox = CheckboxGroup(labels=["Line 0", "Line 1", "Line 2"], active=[0, 1, 2], callback=callback, width=100) 
callback.args = dict(l0=l0, l1=l1, l2=l2, checkbox=checkbox) 

layout = row(checkbox, p) 
show(layout) 
+0

리스너의 구현에 문제가있는 경우 원래 코드를 직접 사용해보고 상자가 js와 chrome의 crossbrowsing 문제 일 가능성이있는 행을 숨기지 않았는지 확인할 수 있습니다. 'checkbox.active.includes (1)'을 사용하여 모든 문장을 'checkbox.active'로 변경하면 작업을 수행 할 수 있습니다. 심지어 대답, 대답은 정말 도움이되었다 –

+0

'checkbox.active.includes'는'SCRIPT438 : 객체가 속성이나 메소드를 지원하지 않습니다 '결과를 포함합니다 : 파일 : 기능 코드 (1), 줄 : 3, 열 : 5 'IE11 –

+0

에서 나는 @ pablo-a에 동의한다. 이것은 올바른 라인을 숨기지 않고 단지 선택된 첫 번째 * n 라인을 가리 킵니다. 라인 0과 2를 선택하면 0과 1이 표시됩니다. (처음 2 개) –

관련 문제