Pointerxy

Download this notebook from GitHub (right-click to download).


Title
Simple pointer example
Description
A linked streams example demonstrating how us a PointerXY stream to reveal more information about coordinate.
Backends
Bokeh
Tags
streams, linked, pointer, interactive
In [1]:
import numpy as np
import holoviews as hv
from holoviews import streams
hv.extension('bokeh')
In [2]:
Y,X=(np.mgrid[0:100, 0:100]-50.)/20.
img = hv.Image(np.sin(X**2+Y**2))

# Declare pointer stream initializing at (0, 0) and linking to Image
pointer = streams.PointerXY(x=0, y=0, source=img)

# Define function to draw cross-hair and report value of image at location as text
def cross_hair_info(x, y):
    text = hv.Text(x+0.05, y, '%.3f'% img[x,y], halign='left', valign='bottom')
    return hv.HLine(y) * hv.VLine(x) * text

# Overlay image and cross_hair_info
img * hv.DynamicMap(cross_hair_info, streams=[pointer])
Out[2]:

Download this notebook from GitHub (right-click to download).