2017-10-08 1 views
0

bokeh로 플롯을 작성했으며 일부 위젯을 추가하려고합니다. 현재 RangeSlider를 사용하여 x 축을 변경하고 싶지만 콜백에 문제가 있다고 생각합니다. 동봉 코드를 찾으십시오 :RangeSlider로 축 범위 변경

import pandas as pd 
import numpy as np 
import bokeh.plotting as bp 
from bokeh.models import CustomJS 
from bokeh.models.widgets import RangeSlider 
from bokeh.layouts import row, widgetbox 
from bokeh.plotting import figure, show, output_file 


df = pd.DataFrame(np.random.randint(0,30,size=(100, 3)), columns=list('ABC')) 
df.index.name ='Numbers' 
dt = bp.ColumnDataSource(df) 

output_file("Plot.html") 

p = figure(title="Example", 
     x_axis_label = "Number", y_axis_label = "Temperature in C", 
     x_range=(0,100)) 

p.line(source=dt, x='Numbers', y='A', color='blue', legend='Line A') 
p.line(source=dt, x='Numbers', y='B', color='red', legend='Line B') 
p.line(source=dt, x='Numbers', y='C', color='green', legend='Line C') 
p.legend.click_policy="hide" 

callback = CustomJS(args=dict(p=p), code=""" 
         var a = cb_obj.value; 
         p.x_range = a; 
         p.change.emit(); 
         """) 

range_slider = RangeSlider(start=0, end=100,value=(2,75), step=1, title="Test") 
range_slider.js_on_change('value', callback) 


layout = row(p,widgetbox(range_slider)) 
show(layout) 

미리 감사드립니다!

답변

0

는 개별적 범위에 startend을 설정해야합니다 :

callback = CustomJS(args=dict(p=p), code=""" 
    var a = cb_obj.value; 
    p.x_range.start = a[0]; 
    p.x_range.end = a[1]; 
""") 

또한, emit에 대한 호출이 필요하지 않습니다.

+0

굉장! 고마워요! :) – Ailurus