我可能错了,但是我认为似乎没有可用于各行的id,隐藏它们的一种方法是执行document.getElementById("idSelected").style.visibility = "hidden";
由于CheckBoxGroup
没有可用的回调函数,所以我决定使用Select
。我可以在CustomJS
中获取所选源,但那就是全部内容了:
from bokeh.io import vform
from bokeh.models import CustomJS, ColumnDataSource, Select
from bokeh.plotting import output_file, figure, show
from numpy.random import normal, uniform
meas_data_1 = normal(0, 1, 10)
meas_data_2 = uniform(-0.5, 0.5, 10)
x1 = range(0, len(meas_data_1))
y1 = meas_data_1
source1 = ColumnDataSource(data=dict(x=x1, y=y1))
x2 = range(0, len(meas_data_2))
y2 = meas_data_2
source2 = ColumnDataSource(data=dict(x=x2, y=y2))
output_file("myplot.html", title="My plot")
fig = figure(width=500, plot_height=500)
fig.line('x', 'y', source=source1, line_width=3, line_alpha=0.6)
fig.line('x', 'y', source=source2, line_width=3, line_alpha=0.6)
select = Select(title="Option:", options=["source1", "source2"])
select.callback = CustomJS(args=dict(source1=source1, source2=source2, select=select), code="""
console.log(select.attributes.value);
""")
show(vform(fig, select))
也许你可以在
CustomJS
中调整数据,根据所选内容将其全部设置为0。或者,如果您可以访问
line_width
属性并将其设置为0,那就基本上是所有想到的了。
ValueError: expected an element of Dict(String, Instance(Model)), got {'renderers': [<bokeh.models.renderers.GlyphRenderer object at 0x11db30090>, ...], 'checkbox': <bokeh.models.widgets.groups.CheckboxButtonGroup object at 0x11c4adc90>}
。 - user2561747name="hideable"
的标签。然后,我将plot=p
传递到args
字典中,而不是一组渲染器。我的Coffeescript代码如下:rends = plot.select("hideable"); rends[i].visible = i in checkbox.active for i in [0...rends.length];
- user2561747plot.legend.click_policy = "hide"
,就可以完成它了。 - user136036