Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataLink involving a DynamicMap #3248

Closed
DancingQuanta opened this issue Dec 2, 2018 · 0 comments
Closed

DataLink involving a DynamicMap #3248

DancingQuanta opened this issue Dec 2, 2018 · 0 comments

Comments

@DancingQuanta
Copy link
Contributor

I want to view a image of 3D data and use a PointDraw to mark pixels of the image.
With @philippjfr help, I am able to make the points snap to the center of a pixel. The points is created by a DynamicMap returning hv.Points.
Finally I wanted to view the coordinates of the points in a hv.Table. To do this, I used a DataLink to link the dynamic Points to the table.

However, the DataLink appears not to work. The table did not update upon adding new points.

Full example code

spatial_dmap = hv.DynamicMap(lambda X: hv.Image(np.random.rand(10, 10)), kdims=['X']).redim.values(X=[1, 2, 3])
stream = hv.streams.PointDraw(data={'x': [], 'y': []})

def snap_points(data):
    key = spatial_dmap.callback.args or tuple(d.values[0] for d in spatial_dmap.kdims)
    img = spatial_dmap[key]
    closest = img.closest(list(zip(data['x'], data['y'])))
    return hv.Points(closest)

points = hv.DynamicMap(snap_points, streams=[stream])

table = hv.Table(points.data, ['x', 'y'])
DataLink(points, table)

(
    spatial_dmap
    * points
    + table
)

Here is another example code that does not snap points to the center of the pixels. This example code works where the table do get updated with new points.

spatial_dmap = hv.DynamicMap(lambda X: hv.Image(np.random.rand(10, 10)), kdims=['X']).redim.values(X=[1, 2, 3])

points = hv.Points([])
point_stream = streams.PointDraw(source=points)

table = hv.Table(points.data, ['x', 'y'])
DataLink(points, table)

(
    spatial_map
    * points
    + table
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants