2017-02-27 2 views
2

버튼 클릭으로 범위가 업데이트되는 2 개의 Y 축으로 플롯을 만들고 싶습니다. 스크립트는 Bokeh 서버에서 실행됩니다. 아래 코드에서 기본 y 축은 f.y_range.start/end를 변경하여 업데이트됩니다. 그러나 2 차 y 축에서는이를 수행 할 수 없습니다. 내가 대신 두 개의 다른 명령을 시도, 즉Bokeh, Python : 여분 축의 범위를 업데이트하는 방법

f.extra_y_ranges.update({"y2Range": Range1d(start=0, end=50)}) 

f.extra_y_ranges.update = {"y2Range": Range1d(start=0, end=50)} 

그러나 그들 중 누구도 작동하지 않습니다.

비슷한 질문은 여기에 질문을 받았다 : Bokeh: How to change extra axis visibility

# Import libraries 
from bokeh.io import curdoc 
from bokeh.models import ColumnDataSource, Range1d, LinearAxis 
from bokeh.models.widgets import Button 
from bokeh.layouts import layout 
from bokeh.plotting import figure 


# Create figure 
f=figure() 

# Create ColumnDataSource 
source = ColumnDataSource(dict(x=range(0,100),y=range(0,100))) 

# Create Line 
f.line(x='x',y='y',source=source) 
f.extra_y_ranges = {"y2Range": Range1d(start=0, end=100)} 
f.add_layout(LinearAxis(y_range_name='y2Range'), 'left') 

# Update axis function 
def update_axis(): 
    f.y_range.start = 0 
    f.y_range.end = 50 

# Create Button 
button = Button(label='Set Axis') 

# Update axis range on click 
button.on_click(update_axis) 

# Add elements to curdoc 
lay_out=layout([[f, button]]) 
curdoc().add_root(lay_out) 

답변

6

나는 비슷한 문제에 직면했다. 나는 그것을 만들었던 이름을 통해 'extra_y_axis'dict을 통해 액세스하여 보조 축의 범위를 업데이트 할 수있었습니다.


# Update primary axis function 
def update_axis(): 
    f.y_range.start = 0 
    f.y_range.end = 50 

# Update secondary axis function 
def update_secondary_axis(): 
    f.extra_y_ranges['y2Range'].start = -20 #new secondary axis min 
    f.extra_y_ranges['y2Range'].end = 80 #new secondary axis max 
+0

감사합니다 많은 : 귀하의 경우, 그것은처럼 보일 것이다! 이제 라인 글리프에 축 지정을 할 때의 새로운 문제에 직면하고 있습니다. 어쩌면 당신은 그것을 해결하는 방법을 알고있을 것입니다. [here] (http://stackoverflow.com/questions/42814842/python-bokeh-how-to-assign-extra-y-axis-to-line-glyph-in-streaming-plot) 설명을 찾으십시오. – Julian

관련 문제