使用MultiSelect小部件隐藏和显示散景中的线条

时间:2016-08-01 17:50:17

标签: python python-2.7 widget bokeh

我正在使用四组数据,每组数据都有几个时间序列。我正在使用散景图将所有这些绘制在一起,结果如下:

multiline graph bokeh with widget

from bokeh.plotting import figure, output_file, show
from bokeh.palettes import RdYlGn4
from bokeh.models import CustomJS, ColumnDataSource, MultiSelect
from bokeh.layouts import row, widgetbox

output_file("graph.html")
p = figure(plot_width=1000, plot_height=400, x_axis_type="datetime", title="title")
cadena=range(4)
for i,comp in enumerate(cadena):
    ts=[t for t in data_plu_price.columns if int(t) in df.T[df.C==comp].values]
    n_lines=len(data[ts].columns) 
    p.multi_line(xs=[data[ts].index.values]*n_lines, ys=[data[t].values for t in ts],line_color=RdYlGn4[i], legend=str(i))
p.title.align = "center"
p.title.text_font_size = "20px"
p.xaxis.axis_label = 'date'
p.yaxis.axis_label = 'price'

callback = CustomJS("""Some Code""")
multi_select = MultiSelect(title="Select:", value=cadena,
                       options=[(str(i), str(i)) for i in range(4)])
layout = row(p,widgetbox(multi_select))
show(layout)

问题是它看起来非常混乱,所以我想使用多选小部件来显示/隐藏所有多线组(4)。我需要在创建multi_line和回调对象中使用哪种代码来进行此交互?

任何指导?

提前致谢。

1 个答案:

答案 0 :(得分:2)

在此PR中版本0.12.1中添加了支持完全执行此操作(使用MultiSelect小部件隐藏/显示行):https://github.com/bokeh/bokeh/pull/4868

这里有一个例子(下面复制):https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/line_on_off.py

select col1, col2, col3, col4
  from firstTable
union
select col1, col2, col3, col4
  from secondTable