用Lass绘制Bokeh的一系列数据

2024-09-30 01:24:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些数据是我和Bokeh一起策划的。这是一些多方面学习分析的结果,这些分析被压缩到两个维度。我要做的是使用套索工具选择一部分数据点,然后绘制一个直方图,比如这些数据点的一个特定特征。在

使用此帖子: Get selected data contained within box select tool in Bokeh

还有这个

https://docs.bokeh.org/en/latest/docs/user_guide/interaction/linking.html

我了解到你可以在选择后得到指数,也有数据相互链接的绘图。我可以使用这些索引选择一个我感兴趣的特性的数据点子集。不过,我希望能够简化这一点。当我做套索选择,我想另一个绘图生成所选指数的直方图。我的问题是如何处理回拨。我似乎不能把顺序弄对,我似乎也不知道如何把这些情节联系起来。在

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,它可以在我选择使用套索时更新索引

^{pr2}$

我在一个Jupyter笔记本电脑环境下工作。在


Tags: 数据rightsourceexecutedatacreateipythontools

热门问题