如何解决使用散景过滤小部件
如何在不依赖ColumnDataSource(df)的情况下使用Bokeh小部件过滤数据框并使用回调?
我的数据框列为:['Date','demand','Battery'],并希望按Battery进行过滤,但是ColumnDataSource需要一个具有独立列的数据框。我的数据名流在这三列中混合了所有内容。
下面的示例代码仅对一列使用回调。我想通过电池的序列号更新和筛选所有可能的需求和日期。
df=pd.DataFrame()
df['x']= demand.loc[demand['Battery']==Battery,['Date']].to_numpy().flatten()
df['y']= demand.loc[demand['Battery']==Battery,['demand']].to_numpy().flatten()
source = ColumnDataSource(df)
bat= Battery
p=figure(x_axis_type='datetime',y_axis_label='Demand',plot_width=1000,plot_height=450)
p.line('x','y',source=source)
p.title.text='Battery' + ' ' + bat
p.title.align = 'center'
show(p)
# Create a dropdown Select widget: select
select_menu= Select(title="Battery:",options=['5e6a62df','aasdfsds4330a'],value='5e6a62df')
callback= CustomJS(args={'source':source2},code="""
// print the selectd value of the select widget -
// this is printed in the browser console.
// cb_obj is the callback object,in this case the select
// widget. cb_obj.value is the selected value.
console.log(' changed selected option',cb_obj.value);
// create a new variable for the data of the column data source
// this is linked to the plot
var data = source.data;
// allocate the selected column to the field for the y values
data['y'] = data[cb_obj.value];
// register the change - this is required to process the change in
// the y values
source.change.emit();
""")
# Attach the update_plot callback to the 'value' property of select
select2.callback=callback
show(row(select2,p))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。