0

我想TapTool在单击每个holoviews.Polygons. 在散景中如何工作的一个完美示例是点数据的散景文档。但是,当我尝试在全息视图中使用它时,它似乎不起作用。我能做的最接近的事情是:

import geoviews as gv
from bokeh.models import OpenURL, TapTool


url = 'https://google.@domain'
taptool = TapTool()
taptool.callback = OpenURL(url=url)
p = gv.Polygons(data, vdims=['Area', 'domain'], crs=ccrs.PlateCarree).options(alpha=1, tools=['hover', taptool])
p

该图显示得很好,并且 URL 打开的触发工作正常,但是“@domain”的解析不起作用并且 URL 是“google.???” 这里有什么问题?

4

2 回答 2

1

没有把握; 当我为这个无意义的例子做这件事时,它似乎有效:

import holoviews as hv, numpy as np
hv.extension("bokeh")

def rectangle(x=0, y=0, width=.05, height=.05):
    return np.array([(x,y), (x+width, y), (x+width, y+height), (x, y+height)])

polys = hv.Polygons([{('x', 'y'): rectangle(x, y), 'level': z}
                     for x, y, z in np.random.rand(100, 3)], vdims='level')

url = 'https://google.@level'
taptool = TapTool()
taptool.callback = OpenURL(url=url)
polys.opts(color='level', line_width=1, tools=['hover', taptool])
于 2021-05-06T18:09:46.233 回答
1

您可以使用此处的 HoloViews 文档中描述figure的选项访问 holoviews 中的散景。hook

通过访问散景图,您可以执行诸如连接任意回调之类的操作。例如,在 python 回调中访问光标坐标,或处理Tap事件:

import holoviews as hv
from bokeh.events import MouseMove, Tap

def hook(plot, element):
  # allows access to the bokeh `figure` object
  # so we can bind figure interaction events
  plot.state.on_event(MouseMove, on_mouse_move)
  plot.state.on_event(Tap, on_click)   

  # The handles contain common plot objects
  # plot.handles

def on_mouse_move(event):
  # do something

def on_click(event):
   # do something

my_hv_plot = hv.Points([])
my_hv_plot.opts(hooks=[hook])
于 2022-02-14T04:46:55.970 回答