Boundsy

Title
BoundsY stream example
Description
A linked streams example demonstrating how to use BoundsY streams.
Backends
Bokeh
Tags
streams, linked, interactive
In [ ]:
import numpy as np
import holoviews as hv
from holoviews import opts, streams

hv.extension('bokeh')
In [ ]:
xs = np.linspace(0, 1, 200)
ys = xs*(1-xs)
curve = hv.Curve((xs,ys))

bounds_stream = streams.BoundsY(source=curve,boundsy=(0,0))

def make_area(boundsy):
    return hv.Area((xs, np.minimum(ys, boundsy[0]), np.minimum(ys, boundsy[1])), vdims=['min','max'])


def make_items(boundsy):
    times = ["{0:.2f}".format(x) for x in sorted(np.roots([-1,1,-boundsy[0]])) + sorted(np.roots([-1,1,-boundsy[1]]))]
    return hv.ItemTable(sorted(zip(['1_entry', '2_exit', '1_exit', '2_entry'], times)))

area_dmap = hv.DynamicMap(make_area, streams=[bounds_stream])
table_dmap = hv.DynamicMap(make_items, streams=[bounds_stream])

(curve * area_dmap + table_dmap).opts(
    opts.Layout(merge_tools=False),
    opts.Overlay(tools=['ybox_select'], active_tools=['ybox_select'])
)

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