用散景选择并不真正有效

时间:2016-10-03 20:33:08

标签: python-3.x bokeh

我使用的是散景0.12.2。我有一个单词选择。当我选择一个单词时,它应该圈出点数据。它似乎工作然后停止。我正在尝试2个单词,word1和word2。 lastidx充满了index.xc和yx是圆圈的位置,这里是代码。如果我更改了select中的值,那么这可以使用一个,但不是真的。

            for j in range(0,2):
                for i in range(0,len(lastidx[j])):
                    xc.append(tsne_kmeans[lastidx[j][i], 0])
                    yc.append(tsne_kmeans[lastidx[j][i], 1])

        source = ColumnDataSource(data=dict(x=xc, y=yc, s=mstwrd))

        def callback(source=source):
            dat = source.get('data')
            x, y, s = dat['x'], dat['y'], dat['s']

            val = cb_obj.get('value')

            if val == 'word1':
                for i in range(0,75):
                    x[i] = x[i]
                    y[i] = y[i]
            elif val == 'word2':
                for i in range(76,173):
                    x[i-76] = x[i]
                    y[i-76] = y[i]

            source.trigger('change')

        slct = Select(title="Word:", value="word1", options=mstwrd , callback=CustomJS.from_py_func(callback))



        #  create the circle around the data where the word exist
        r = plot_kmeans.circle('x','y', source=source)


        glyph = r.glyph
        glyph.size = 15
        glyph.fill_alpha = 0.0
        glyph.line_color = "black"
        glyph.line_dash = [4, 2]
        glyph.line_width = 1

x和y在这里加载了所有数据,我只选择我选择的单词的数据。它似乎工作,然后它没有。 find word

这可以作为一个独立的图表吗? 谢谢

1 个答案:

答案 0 :(得分:0)

我明白了:这里的代码只是为了看看这是否有效。这当然会得到改善。也许这就是最后写的: https://github.com/bokeh/bokeh/issues/2618

    for i in range(0,len(lastidx[0])):
                xc.append(tsne_kmeans[lastidx[0][i], 0])
                yc.append(tsne_kmeans[lastidx[0][i], 1])
            addto = len(lastidx[1])-len(lastidx[0])
            # here i max out the data which has the least
            # so when you go from one option to the other it 
            # removes all the previous data circle
            for i in range(0,addto):
                xc.append(-16) # just send them somewhere
                yc.append(16)
            for i in range(0, len(lastidx[1])):
                xf.append(tsne_kmeans[lastidx[1][i], 0])
                yf.append(tsne_kmeans[lastidx[1][i], 1])
        x = xc
        y = yc
        source = ColumnDataSource(data=dict(x=x, y=y,xc=xc,yc=yc,xf=xf,yf=yf))

        val = "word1"
        def callback(source=source):
            dat = source.get('data')
            x, y,xc,yc,xf,yf = dat['x'], dat['y'], dat['xc'], dat['yc'], dat['xf'], dat['yf']
            # if slct.options['value'] == 'growth':
            val = cb_obj.get('value')

            if val == 'word1':
                for i in range(0,len(xc)):
                    x[i] = xc[i]
                    y[i] = yc[i]
            elif val == 'word2':
                for i in range(0,len(xf)):
                    x[i] = xf[i]
                    y[i] = yf[i]

            source.trigger('change')

        slct = Select(title="Most Used Word:", value=val, options=mstwrd , callback=CustomJS.from_py_func(callback))



        #  create the circle around the data where the word exist
        r = plot_kmeans.circle('x','y', source=source)

我将检查是否可以传递矩阵。不要忘记拥有相同大小的数据,否则您将同时圈出多个选项。 谢谢