2017-02-27 26 views
2

ボタンのクリックで範囲が更新されている2つのy軸を持つプロットを作成したいとします。スクリプトはBokehサーバー上で実行されます。以下のコードでは、f.y_range.start/endを変更することによって、プライマリのy軸が更新されていることに注意してください。ただし、これはセカンダリの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'ディクチトを使ってそれを作成した名前でアクセスすることで更新できました。


# 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

どうもありがとう:あなたのケースのために、それは次のようになります!私は今、ライングリフへの軸の割り当てに関する新しい問題に直面しています。多分あなたはそれを解決する方法を知っているかもしれません。 [ここ]の説明を見つけてください(http://stackoverflow.com/questions/42814842/python-bokeh-how-to-assign-extra-y-axis-to-line-glyph-in-streaming-plot)。 – Julian

関連する問題