2016-10-03 3 views
0

보케 0.12.2를 사용하고 있습니다. 단어가있는 선택이 있습니다. 단어를 선택하면 도트 데이터를 원으로 표시해야합니다. 그것은 그 때 작동 중지하는 것을 보인다. 나는 2 단어, word1과 word2로 노력하고있다. lastidx는 index.xc로 가득 차 있으며 yx는 원의 위치입니다. 여기 코드가 있습니다. 이것은 하나와 함께 일하고있다하지만 난 선택의 값을 변경하지 정말 경우 :보케로 선택하지 마십시오.

  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

독립형 차트로 그 작업을 수행 할 수 있습니까? 감사합니다.

답변

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) 

내가 확인합니다. 동시에 여러 옵션을 동그라미로 표시하지 않는 경우 동일한 크기의 데이터를 사용하는 것을 잊지 마십시오. 감사합니다.

관련 문제