问题描述
我正在遵循bokeh教程https://docs.bokeh.org/en/0.10.0/docs/user_guide/interaction.html中给出的示例来更新所选点的平均值。代码如下所示
from random import random
from bokeh.models import CustomJS,ColumnDataSource
from bokeh.plotting import figure,output_file,show
output_file("callback.html")
x = [random() for x in range(500)]
y = [random() for y in range(500)]
color = ["navy"] * len(x)
s = ColumnDataSource(data=dict(x=x,y=y,color=color))
p = figure(plot_width=400,plot_height=400,tools="lasso_select",title="Select Here")
p.circle('x','y',color='color',size=8,source=s,alpha=0.4)
s2 = ColumnDataSource(data=dict(ym=[0.5,0.5]))
p.line(x=[0,1],y='ym',color="orange",line_width=5,alpha=0.6,source=s2)
s.callback = CustomJS(args=dict(s2=s2),code="""
var inds = cb_obj.get('selected')['1d'].indices;
var d = cb_obj.get('data');
var ym = 0
if (inds.length == 0) { return; }
for (i = 0; i < d['color'].length; i++) {
d['color'][i] = "navy"
}
for (i = 0; i < inds.length; i++) {
d['color'][inds[i]] = "firebrick"
ym += d['y'][inds[i]]
}
ym /= inds.length
s2.get('data')['ym'] = [ym,ym]
cb_obj.trigger('change');
s2.trigger('change');
""")
show(p)
当我选择点时,平均线似乎没有更新,但是在bokeh网页上它起作用了。我对Bokeh不太陌生,因此如果有人能提出建议为什么不起作用,我将不胜感激。 另外,我最终想要实现的是基于盒子选择工具找到最小和最大选择的平均值。如果您还可以就如何修改上述代码以适合我的需求提出建议,那将是很好的。
关于, 尼特
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)