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

Updating Legend through Streams #2927

Closed
ahuang11 opened this issue Aug 5, 2018 · 2 comments
Closed

Updating Legend through Streams #2927

ahuang11 opened this issue Aug 5, 2018 · 2 comments

Comments

@ahuang11
Copy link
Collaborator

ahuang11 commented Aug 5, 2018

From this example:
http://holoviews.org/gallery/demos/bokeh/box_draw_roi_editor.html

If you remove NdOverlay [legend_limit=0], the legend labels persist even after deleting a box.
image

import numpy as np
import holoviews as hv
from holoviews import streams
hv.extension('bokeh')

Declaring data 
In this example we will use the BoxDraw stream to draw ROIs over a set of neural calcium imaging data, and use them to compute and display timeseries of the activity in the regions of interests.

data = np.load('../../../assets/twophoton.npz')
calcium_array = data['Calcium']
ds = hv.Dataset((np.arange(50), np.arange(111), np.arange(62), calcium_array),
                ['Time', 'x', 'y'], 'Fluorescence')

polys = hv.Polygons([])
box_stream = streams.BoxEdit(source=polys)

def roi_curves(data):
    if not data or not any(len(d) for d in data.values()):
        return hv.NdOverlay({0: hv.Curve([], 'Time', 'Fluorescence')})
    
    curves = {}
    data = zip(data['x0'], data['x1'], data['y0'], data['y1'])
    for i, (x0, x1, y0, y1) in enumerate(data):
        selection = ds.select(x=(x0, x1), y=(y0, y1))
        curves[i] = hv.Curve(selection.aggregate('Time', np.mean))
    return hv.NdOverlay(curves)

hlines = hv.HoloMap({i: hv.VLine(i) for i in range(50)}, 'Time')
dmap = hv.DynamicMap(roi_curves, streams=[box_stream])
Plot 
To define an ROI, select the 'Box edit' tool and double click to start defining the ROI and double click to finish placing the ROI:

%%opts Curve [width=400] {+framewise}
%%opts Polygons (fill_alpha=0.2 line_color='white') VLine (color='black')
ds.to(hv.Image, ['x', 'y'], dynamic=True) * polys + dmap * hlines
@philippjfr
Copy link
Member

Now implemented.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants