gpt4 book ai didi

python - Bokeh ,Python : How to update range of extra axis

转载 作者:太空宇宙 更新时间:2023-11-03 12:55:54 25 4
gpt4 key购买 nike

我想创建一个带有 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)}

但是它们都不起作用。

此处提出了类似的问题: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)

最佳答案

我遇到了类似的问题。我能够通过我创建它时使用的名称通过“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

关于python - Bokeh ,Python : How to update range of extra axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42493049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com