问题
I am new to using Bokeh.
I have data which roughly looks like that
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
...
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.
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))
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.
回答1:
(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.
来源:https://stackoverflow.com/questions/47434701/bokeh-select-interactivle-multiple-datasets-for-plotting