使用HoloViews / Bokeh渲染器(通过Windows上当前的anaconda的Holoviews = 1.11.2 / Bokeh 1.0.4),我想创建一个由散点图和RGB图像组成的布局。散点图显示电影中的明暗对比值。 RGB图像显示了来自电影的屏幕截图。目的是能够单击散点图中的一个点,并加载电影中该时间戳记的图像。
只要散点图不超过与点击工具和selection1D流关联的hv.Points
元素,一切都可以正常工作。
%%opts Points [width=1108, size_index=2, tools=['hover', 'tap'], toolbar='left'] (alpha=0.2)
%%opts RGB [toolbar='left']
scatter = hv.Points(il_colful, kdims=['frame', 'bin'], vdims=['pixels', 'time'])
tap_point = streams.Selection1D(source=scatter)
def frmimg(index):
if index:
frame = il_colful.iloc[index[0]]['frame']
url = './il_divo/frames/576p30/il_divo_' + '{0:05}'.format(frame) + '.png'
else:
url = './il_divo/frames/576p30/il_divo_00100.png'
return hv.RGB.load_image(url).options(height=480, width=1108, xaxis=None, yaxis=None)
(hv.DynamicMap(frmimg,
streams=[tap_point])
+ scatter).cols(1)
但是,当我将散点图转换为DynamicMap时(因为我想对散点图的某些参数进行交互式修改),我再也无法使用散点图上的点击工具了,我没有得到任何十字线符号在散点图上,我无法进行任何选择。
points = hv.Points(il_colful1, kdims=['frame', 'bin'])
selected = streams.Selection1D(source=points)
def scatter(div=5000, thrsh=0, alpha=0.1):
global points
il_colful1['scaler'] = (il_colful1['pixels'] / div).round(0).astype(int)
il_colful_lim1 = il_colful1[il_colful1['pixels'] > thrsh]
points = hv.Points(il_colful_lim1, kdims=['frame', 'bin'], vdims=['pixels', 'time', 'scaler'], label='Il Divo').opts(tools=['tap'], width=1000, color='blue', size_index='scaler', fill_alpha=alpha, line_alpha=alpha)
return points
def img(index):
if index:
frame = il_colful1.iloc[index[0]]['frame']
url = './il_divo/frames/576p30/il_divo_' + '{0:05}'.format(frame) + '.png'
else:
url = './il_divo/frames/576p30/il_divo_00100.png'
return hv.RGB.load_image(url).options(height=433, width=1000, xaxis=None, yaxis=None)
il_divo_sct = hv.DynamicMap(scatter, kdims=['div', 'thrsh', 'alpha']).redim.range(div=(500, 15000), thrsh=(0, 50000), alpha=(0.01, 1.0)).opts(tools=['tap'])
screenshot = hv.DynamicMap(img, streams=[selected])
(screenshot + il_divo_sct).cols(1)
是否无法在DynamicMap中的DynamicMaps / Layers上使用点击工具,或者我错过了某些事情