列数据源和Box_Select的散景使用 [英] Bokeh use of Column Data Source and Box_Select

查看:116
本文介绍了列数据源和Box_Select的散景使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何设置列数据源一无所知,因此我可以从一个图形中选择点,并在另一图形中突出显示相应的点.我正在尝试更多地了解其工作原理.

I'm lost as to how to set up a Column Data Source so that I can select points from one graph and have the corresponding points highlighted in another graph. I am trying to learn more about how this works.

我使用的示例代码是名为关联的笔刷.我想在下面查看我自己的代码是否可以获得相同的效果.该网页说明还涉及

The sample code I am using is the example called Linked Brushing. I'd like to see if I can get the same effect with my own code, below. That web page explanation also refers to Linked Selection with Filtered Data but I don't understand what the code filters=[BooleanFilter([True if y > 250 or y < 100 else False for y in y1] on that page does, so I'm not sure how to adapt it, or if it's even relevant.

这是我的代码:

from bokeh.plotting import figure, output_file, show, Column
from bokeh.models import ColumnDataSource, CDSView, BooleanFilter
from MyFiles import *

class bokehPlot:
    def __init__(self, filename, t, a, b, c, d):

        self.source = ColumnDataSource(data=dict(x=t, y1=a, y2=b, y3=c, y4=d))

        p1 = self.makePlot(filename, 'x', 'y1', 'A')
        p2 = self.makePlot(filename, 'x', 'y2', 'B', x_link=p1)
        p3 = self.makePlot(filename, 'x', 'y3', 'C', x_link=p1)
        p4 = self.makePlot(filename, 'x', 'y4', 'D', x_link=p1)

        output_file('scatter_plotting.html', mode='cdn')

        p = Column(p1, p2, p3, p4)
        show(p)

    def makePlot(self,filename,x0,y0,y_label, **optional):

        TOOLS = "box_zoom,box_select,reset"

        p = figure(tools=TOOLS, plot_width=1800, plot_height=300)

        if ('x_link' in optional):
            p0 = optional['x_link']
            p.x_range = p0.x_range

        p.scatter(x=x0, y=y0, marker='square', size=1, fill_color='red', source=self.source)
        p.title.text = filename
        p.title.text_color = 'orange'
        p.xaxis.axis_label = 'T'
        p.yaxis.axis_label = y_label
        p.xaxis.minor_tick_line_color = 'red'
        p.yaxis.minor_tick_line_color = None
        return p

我的主程序如下所示(设置为从文件中传递最多100K数据点):web

And my main looks like this (set to pass along up to 100K data points from the file):web

p = readMyFile(path+filename+extension, 100000)
t = p.time()
a = p.a()
b = p.b()
c = p.c()
d = p.d()
v = bokehPlot(filename, t, a, b, c, d)

变量t,a,b,c和d是numpy ndarray类型.

The variables t, a, b, c, and d are type numpy ndarray.

我设法链接了这些图,因此我可以从一张图上平移和缩放它们.我想从一个图中获取一组数据,并查看它们的突出显示,以及在其他图形上突出显示的相应值(在相同的t值处).

I've managed to link the plots so I can pan and zoom them all from one graph. I would like to grab a cluster of data from one plot and see them highlighted, along with the corresponding values (at the same t values) highlighted on the other graphs.

在此代码中,我可以绘制一个选择框,但是它只保留了一会儿,然后消失了,所以我看不到任何绘图. box_select如何与源链接,以及导致图重绘的原因?

In this code, I can draw a selection box, but it just remains for a moment, then disappears, and I see no effect on any plot. How is the box_select linked to the source and what causes the plots to redraw?

这只是使自己熟悉Bokeh的第一步.我的下一个目标是使用TSNE对数据进行聚类,并在每个图形中显示具有同步颜色的聚类.但是首先,我想了解此处使用列数据集的机制.例如,在示例代码中,我看不到box_select操作与源变量之间的任何显式连接,以及导致绘图重新绘制的原因.

This is just one step in trying to familiarize myself with Bokeh. My next goal will be to use TSNE to cluster my data and show the clusters with synchronized colors in each graph. But first, I want to understand the mechanics of using the column data set here. In the sample code, for example, I don't see any explicit connection between the box_select operation and the source variable and what causes the plot to redraw.

推荐答案

我的理解是,可以在渲染前使用BooleanFilterIndexFilterGroupFilter来过滤其中一个绘图中的数据.如果只希望第二个图响应第一个图中的事件,则应按照注释中的建议使用gridplot.只要这些图具有相同的ColumnDataSource,就应该将它们链接起来.

My understanding is that the BooleanFilter, the IndexFilter and the GroupFilter can be used to filter the data in one of your plots before rendering. If you only want the second plot to respond to events in the first plot then you should just use gridplot as suggested in the comment. As long as the plots have the same ColumnDataSource they should be linked.

from bokeh.layouts import gridplot
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show

source = ColumnDataSource(data=dict(x=[1, 2, 3, 4, 5], 
                                    y=[1, 2, 3, 4, 5], 
                                    z=[3, 5, 1, 6, 7]))

tools = ["box_select", "hover", "reset"]
p_0 = figure(plot_height=300, plot_width=300, tools=tools)
p_0.circle(x="x", y="y", size=10, hover_color="red", source=source)

p_1 = figure(plot_height=300, plot_width=300, tools=tools)
p_1.circle(x="x", y="z", size=10, hover_color="red", source=source)

show(gridplot([[p_0, p_1]]))

这篇关于列数据源和Box_Select的散景使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆