问题描述
此问题已在 Bokeh Discourse 上发布和回答。
我使用 JavaScript 回调(下面的 MWE)编写了一个带有 bokeh
的交互式数据可视化脚本。从大约 10k 数据点开始,数据过滤明显变慢,超过 100k 就无法使用。在 Jupyter Notebook 中运行代码时也会观察到这一点。这种效应在数据点较多的地区最为明显。
谢谢。
import numpy as np
from bokeh.io import output_file,show
from bokeh.models import CDSView,ColumnDataSource as CDS,CustomJSFilter
from bokeh.models import CustomJS,RangeSlider,Range1d
from bokeh.plotting import figure
from bokeh.layouts import layout
output_file('test.hml') # alternatively one Could use output_notebook()
#generate the data
npoints = 50000
data = dict(exp=np.random.exponential(1,size=npoints),gau=np.random.normal(0,0.5,)
source = CDS(data=data)
slider = RangeSlider(start=0,end=10,value=(0,10),step=.1,title="Exp")
callback = CustomJS(args=dict(s=source),code="""
s.change.emit();
""")
slider.js_on_change('value',callback)
filt = CustomJSFilter(args=dict(slider=slider),code="""
var indices = [];
var start = slider.value[0];
var end = slider.value[1];
for (var i=0; i < source.get_length(); i++){
if (source.data['exp'][i] >= start && source.data['exp'][i] <= end){
indices.push(true);
} else {
indices.push(false);
}
}
return indices;
""")
view = CDSView(source=source,filters=[filt])
fig = figure(plot_width=450,plot_height=350)
fig.circle(x='exp',y='gau',source=source,view=view)
#fix ranges (otherwise they change during filtering)
fig.x_range=Range1d(-1,11)
fig.y_range=Range1d(-3.5,3.5)
lay = layout([[slider],[fig]])
show(lay)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)