簡體   English   中英

Bokeh,Python:如何更新額外軸的范圍

[英]Bokeh, Python: How to update range of extra axis

我想用2個y軸創建一個繪圖,其范圍在按鈕點擊時更新。 該腳本將在Bokeh服務器上運行。 請注意,在下面的代碼中,通過更改f.y_range.start / end來更新主y軸。 但是,對於輔助y軸,這是不可能的。 我嘗試了另外兩個命令,即

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

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

但它們都不起作用。

這里提出了類似的問題: 散景:如何改變額外的軸可見度

# 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)

我遇到了類似的問題。 我能夠通過'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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM