I have some data that I've been plotting with Bokeh. It's the result of some manifold learning analysis scrunched down to 2 dimensions. What I want to do is select a portion of the datapoints using the lasso tool, and then plot a histogram of say one particular feature of those data points.
Using this post: Get selected data contained within box select tool in Bokeh
and this
https://docs.bokeh.org/en/latest/docs/user_guide/interaction/linking.html
I learned you can get the indices after selecting and also have plots where data is linked to one another. I am able to use these indices to then select the subset of datapoints with one feature i'm interested in. However, I'd like to be able to streamline this. When i do the lasso select, I want another plot to generate the histogram of the selected indices. My problem is in dealing with the callbacks. I can't seem to get the order right, and I can't seem to figure out how to link the plots to one another.
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)");
"""
)
and there is some other function i was trying to call called updateInds which would update the indices as i select using lasso
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()
I'm working within a Jupyter notebook environment.