简体   繁体   English

散景,选择交互式多个数据集进行绘图

[英]Bokeh, select interactivle multiple datasets for plotting

I am new to using Bokeh.我是使用 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.我使用 Bokeh 脚本绘制数据,并从下拉菜单中选择要绘制数据的名称(var1、var2、...)。

The script is based on this example:https://github.com/bokeh/bokeh/tree/master/examples/app/weather and looks like this该脚本基于此示例:https ://github.com/bokeh/bokeh/tree/master/examples/app/weather看起来像这样

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 (eg var1 and var2) to be selected to plot them in the same plot for easy comparison.这工作正常,但我希望现在允许选择多个名称(例如 var1 和 var2)以将它们绘制在同一图中以便于比较。 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. (潜在)清理过道 47434701。看起来 Bokeh 有一个MultiSelect方法,在这种情况下可能会有用。 I presume it wasn't available at the original time of question.我认为它在最初提出问题时不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM