[英]Bokeh: chart from pandas dataframe won't update on trigger
我有一個熊貓數據框,我想使用Bokeh服務器將其列顯示為圖中的線條。 另外,我想有一個滑塊來將其中一條線相對於另一條線移動。
我的問題是滑塊值更改時的更新功能。 我已經嘗試過bokeh的滑塊示例中的代碼,但是它不起作用。
這是一個例子
import pandas as pd
from bokeh.io import vform
from bokeh.plotting import Figure, output_file, show
from bokeh.models import CustomJS, ColumnDataSource, Slider
df = pd.DataFrame([[1,2,3],[3,4,5]])
df = df.transpose()
myindex = list(df.index.values)
mysource = ColumnDataSource(df)
plot = Figure(plot_width=400, plot_height=400)
for i in range(len(mysource.column_names) - 1):
name = mysource.column_names[i]
plot.line(x = myindex, y = str(name), source = mysource)
offset = Slider(title="offset", value=0.0, start=-1.0, end=1.0, step=1)
def update_data(attrname, old, new):
# Get the current slider values
a = offset.value
temp = df[1].shift(a)
#to finish#
offset.on_change('value', update_data)
layout = vform(offset, plot)
show(layout)
在update_data
mysource
內部,我必須更新mysource
,但是我不知道該怎么做。 有人能指出我正確的方向嗎?
嘗試一下...將a=offset.value
更改為a=cb_obj.get('value')
然后,在您要執行的操作之后,將source.trigger('change')
放在該update_data
函數中,而不是offset.on_change('value', update_data)
。
還更改offset = Slider(title="offset", value=0.0, start=-1.0, end=1.0, step=1, callback=CustomJS.from_py_func(offset))
請注意,我使用的這種格式已安裝了flexx
。 https://github.com/zoofio/flexx如果您具有Python 3.5,則必須下載zip文件,解壓縮並鍵入python setup.py install
,因為尚未發布該版本的python setup.py install
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.