散景,选择激活多个数据集以进行绘图 [英] Bokeh, select interactivle multiple datasets for plotting
问题描述
我刚开始使用Bokeh.
I am new to using Bokeh.
我有大致类似的数据
date names numbers
2016 var1 62
2012 var2 82
2014 var1 118
2015 var2 69852
2012 var3 167
2016 var1 2266
2011 var1 88282
2015 var3 6307
...
我使用Bokeh脚本绘制数据,然后从下拉菜单中选择要绘制数据的名称(var1,var2,...).
I use a Bokeh script to plot the data and from a dropdown menu I can select for which names (var1, var2, ...) to to plot the data.
该脚本基于以下示例: https://github .com/bokeh/bokeh/tree/master/examples/app/weather ,看起来像这样
The script is based on this example: https://github.com/bokeh/bokeh/tree/master/examples/app/weather and looks like this
import pandas as pd
from bokeh.io import curdoc
from bokeh.layouts import row, column
from bokeh.models import ColumnDataSource, Select
from bokeh.plotting import figure
def get_dataset(src, name):
df = src[src.names == name].copy()
del df['names']
df = df.set_index(['date'])
df.sort_index(inplace=True)
return ColumnDataSource(data=df)
def make_plot(source, title):
plot = figure(plot_width=800, tools="", toolbar_location=None)
plot.title.text = title
plot.line(x='date', y='numbers', source=source, legend="Record")
return plot
def update_plot(attrname, old, new):
ver = vselect.value
plot.title.text = "xxx"
src = get_dataset(df, ver)
source.date.update(src.date)
df = pd.read_csv('data/test_data.csv', delimiter='\t')
ver = 'aps'
cc = df['names'].unique()
vselect = Select(value=ver, title='VER', options=sorted((cc)))
source = get_dataset(df, ver)
plot = make_plot(source, "xxx")
vselect.on_change('value', update_plot)
controls = column(vselect)
curdoc().add_root(row(plot, controls))
这很好用,但我现在允许选择多个名称(例如var1和var2)以将它们绘制在同一图中,以便于比较. 但是,我不知道该如何处理.
This works fine, but I would like to allow now to select multiple names (e.g var1 and var2) to be selected to plot them in the same plot for easy comparison. However, I have no idea how to go about this.
推荐答案
(Potential) cleanup on aisle 47434701. Looks like Bokeh has a MultiSelect method that might be useful in this situation. I presume it wasn't available at the original time of question.
这篇关于散景,选择激活多个数据集以进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!