我有一些我一直在用Bokeh绘图的数据。这是将一些多样性学习分析归结为2维的结果。我想要做的是使用套索工具选择一部分数据点,然后绘制这些数据点的一个特定特征的直方图。
使用这篇文章: Get selected data contained within box select tool in Bokeh
和这个
我了解到,您可以在选择后获取索引,并且还可以获得数据彼此链接的图表。我能够使用这些索引然后选择我感兴趣的一个特征的数据点子集。但是,我希望能够简化这一点。当我做套索选择时,我想要另一个图来生成所选索引的直方图。我的问题是处理回调。我似乎无法使订单正确,我似乎无法弄清楚如何将这些情节相互联系起来。
x = range(0, len(x_toPlot[:,0]))
y0 = x_toPlot[:,0]
y1 = x_toPlot[:,1]
# create a column data source for the plots to share
source = ColumnDataSource(data=dict(x=x, y0=y0, y1=y1))
testSource= ColumnDataSource(data=dict(x=x, y0=y0))
TOOLS = "lasso_select,help"
# create a new plot and add a renderer
left = figure(tools=TOOLS, width=300, height=300, title=None)
left.circle('y0', 'y1', source=source)
# create another new plot and add a renderer
middle = figure(tools=TOOLS, width=300, height=300, title=None)
middle.circle('x', 'y1', source=source)
right = figure(tools=TOOLS, width=300, height=300, title=None)
right.circle('x','y0', source=testSource)
p = gridplot([[left, middle]])
#create a function aboeve.. and then call that funciton in here...
source.callback = CustomJS(args=dict(p=p), code="""
var inds = cb_obj.get('selected')['1d'].indices;
var d1 = cb_obj.get('data');
console.log(d1)
var kernel = IPython.notebook.kernel;
IPython.notebook.kernel.execute("inds = " + inds);
IPython.notebook.kernel.execute("updateInds(inds)");
IPython.notebook.kernel.execute("res=X['education_num']");
IPython.notebook.kernel.execute("res=res.loc[inds2]");
IPython.notebook.kernel.execute("testSource= ColumnDataSource(data=dict(x=inds2, y0=res))");
IPython.notebook.kernel.execute("right = figure(tools=TOOLS, width=300, height=300, title=None)");
IPython.notebook.kernel.execute("right.circle('x','y0', source=testSource)");
IPython.notebook.kernel.execute("p2 = gridplot([[ right]])");
IPython.notebook.kernel.execute("push_notebook(p2)");
"""
)
还有一些我试图调用的其他函数叫做updateInds,它会更新索引,因为我选择使用套索
def updateInds(f):
global inds2
inds2=list(f)
print ("hello")
global testingThing
testingThing=zip([source.data['x'][i] for i in inds], [source.data['y0'][i] for i in inds])
push_notebook()
我在Jupyter笔记本环境中工作。