gpt4 book ai didi

Python Bokeh : Slider callback in ColumnDataSource not update

转载 作者:行者123 更新时间:2023-12-01 08:36:45 25 4
gpt4 key购买 nike

我的回调有问题,我一切正常,除了图表没有更新的部分,即使当我更改 slider 时数组已更新。

import numpy as np

from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure

data = {'x_values': [0,0,2,2,4,4],
'y_values': [10,0,0,5,5,10]} #Seting up data

source = ColumnDataSource(data=data) # Map plot

plot = figure(title="Step Well",
tools="save,wheel_zoom")

plot.line('x_values', 'y_values',source=source)

def update_data(attrname, old, new):
Step = StepHeight.value

x = [0,0,2,2,4,4]
y = [10,0,0,Step,Step,10]
source.data = ColumnDataSource(dict(x=x, y=y))
source.on_change('value', update_data)

StepHeight = Slider(title="Step Height",
value=4.0,
start=2.0, end=6.0, step=0.2)
# Set up layouts and add to document
inputs = widgetbox(StepHeight)

layout = row(inputs, plot)

curdoc().title = "Sliders"
curdoc().add_root(layout)

最佳答案

您试图将 source.data 设为列数据源,但 source 应该是列数据源。 Source.data 只是一个字典。我更改了您的代码中的一些内容,现在应该可以正常工作了。

import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure

data = {'x_values': [0,0,2,2,4,4],
'y_values': [10,0,0,5,5,10]} #Seting up data

source = ColumnDataSource(data=data) # Map plot

plot = figure(title="Step Well",
tools="save,wheel_zoom")

plot.line('x_values', 'y_values',source=source)

def update_data(attrname, old, new):
y = [10,0,0,new,new,10]
source.data['y_values'] = y

StepHeight = Slider(title="Step Height",
value=4.0,
start=2.0, end=6.0, step=0.2)

StepHeight.on_change('value', update_data)

# Set up layouts and add to document
inputs = widgetbox(StepHeight)

layout = row(inputs, plot)

curdoc().title = "Sliders"
curdoc().add_root(layout)

关于Python Bokeh : Slider callback in ColumnDataSource not update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53683815/

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