【发布时间】:2016-04-08 10:26:39
【问题描述】:
我有一个 pandas 数据框,我想使用 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,但我不知道该怎么做。谁能指出我正确的方向?
【问题讨论】:
标签: python pandas bokeh interaction