【问题标题】:Bokeh + Datashader + Bokeh - Capture Mouse Double TapBokeh + Datashader + Bokeh - 捕捉鼠标双击
【发布时间】:2018-01-18 08:18:12
【问题描述】:

我正在使用 Bokeh、DataShader 和 HoloViews 为大数据实现 ScatterPlot。 ScatterPlot 部分本身已经完成,但有一个要求我遇到了问题:我需要能够捕获用户双击的数据坐标。

我在 Jupyter 笔记本中找到了一些对我有用的代码,但由于某种原因,在迁移到 Python 和 Bokeh Server 时,它没有。

代码如下:

    from os.path import dirname, join
import csv

import holoviews as hv
import datashader as ds

import pandas as pd


#import parambokeh
from holoviews.operation.datashader import aggregate, shade, datashade, dynspread
from holoviews.operation import decimate
from holoviews.streams import RangeXY
from holoviews import streams
from bokeh.plotting import curdoc
hv.extension('bokeh')



class MyScatterPlotBokeh:


#
#   PARAMETERS:
#                - keyFieldName    : Field  that uniquely identify a row
#                - xFieldName      : Field Name used for x-Axis
#                - yFieldName      : Field Name used for y-Axis
#                - colorFieldName  : Field Name used to select circle colors
#                - otherFieldNames : Comma separated value variable with the name of all fields we want to show data 
#
    def __init__(self, filePath, title, screenWidth, screenHeight, keyFieldName, xFieldName, yFieldName, colorFieldName, otherFieldNames):


           self._screenHeight = screenHeight
           self._screenWidth  = screenWidth

#  Read data from file
           df = pd.read_csv(filePath)
           df[colorFieldName]=df[colorFieldName].astype("category")

#  Creating graphic
           hover_opts = hv.opts("QuadMesh [tools=['hover']] (alpha=0 hover_alpha=0.2)")            
           self._points = hv.Points(df,kdims=[xFieldName,yFieldName])         
           self._dynamic_hover = datashade(self._points) * dynspread(datashade(self._points, aggregator=ds.count_cat(colorFieldName))) * \
             hv.util.Dynamic(aggregate(self._points, width=50, height=50, streams=[RangeXY]),operation=hv.QuadMesh) 


# Interaction - Point selection
           double_tap = streams.DoubleTap(transient=True, source=self._points)

           self._countTap = 0
           self._taps = []


           def record_taps(x,y):      
               print "clicked"
               self._countTap += 1
               if self._countTap>2: 
                 self._countTap = 0
               if None not in [x,y]:
                  if self._countTap == 1:
                     self._taps.insert(0,(x, y))
                  else:
                     self._taps.append((x, y))
               print "TAPS LOOK LIKE "  + str(self._taps)
               return hv.Points(self._taps, vdims='Taps')


           self._finalPlot = self._dynamic_hover + hv.DynamicMap(record_taps, streams=[double_tap])



    def draw(self):
        hv.renderer('bokeh').server_doc(self._finalPlot)

服务器一执行,我就可以看到“点击”消息显示,但在浏览器上双击之后就再也没有了。就像 双击 事件没有响应。 最终我需要将点击的 X 和 Y 坐标发送到浏览器,我认为我可以通过从 python 代码创建一个输入框来完成,但我还没有。

任何帮助将不胜感激。

【问题讨论】:

  • 我怀疑这是最近解决的错误(请参阅github.com/ioam/holoviews/pull/2239)。你介意试试 HoloViews 大师吗?我们将尽快发布 v1.9.3 错误修复版本。
  • 我会尝试并告诉你。谢谢philippjfr
  • @philippjfr 安装了最后一个版本,现在我收到此错误,抱歉,但不知道原因:/anaconda2/envs/ds/lib/python2.7/site-packages/holoviews/operation/datashader。 py:386: FutureWarning: xarray.DataArray.__contains__ 当前检查 DataArray.coords 中的成员资格,但在 xarray v0.11 中将更改为检查数组值中的成员资格。如果 agg 中的“x_axis”和 agg 中的“y_axis”:没有可用的存储后端能够支持提供的数据格式。 XArrayInterface 引发以下错误:无法从与其坐标之一同名的 DataArray 创建数据集
  • 问题出在这一行: dynspread(datashade(self._points, aggregator=ds.count_cat(colorFieldName))) 而double_click仍然不起作用:(
  • 只是要明确当前版本是:1.9.2-9-gd2409456f

标签: bokeh scatter-plot double-click holoviews datashader


【解决方案1】:

使用 1.9.2 版解决了 philippjfr

指出的问题

我怀疑这是最近解决的错误(请参阅 github.com/ioam/holoviews/pull/2239)。你介意试试 HoloViews 大师吗?我们将尝试尽快发布 v1.9.3 错误修复版本。 ——philippjfr

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多