{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### **Title**: BoundsX stream example\n",
    "\n",
    "**Description**: A linked streams example demonstrating how to use BoundsX streams.\n",
    "\n",
    "**Dependencies**: Bokeh\n",
    "\n",
    "**Backends**: [Bokeh](./BoundsX.ipynb), [Plotly](../plotly/BoundsX.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import holoviews as hv\n",
    "from holoviews import streams\n",
    "hv.extension('bokeh')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "n=200\n",
    "xs = np.linspace(0, 1, n)\n",
    "ys = np.cumsum(np.random.randn(n))\n",
    "df = pd.DataFrame({'x': xs, 'y': ys})\n",
    "curve = hv.Curve(df)\n",
    "\n",
    "def make_from_boundsx(boundsx):\n",
    "    sub = df.set_index('x').loc[boundsx[0]:boundsx[1]]\n",
    "    return hv.Table(sub.describe().reset_index().values, 'stat', 'value')\n",
    "\n",
    "dmap = hv.DynamicMap(make_from_boundsx, streams=[streams.BoundsX(source=curve, boundsx=(0,0))])\n",
    "\n",
    "curve.opts(tools=['xbox_select']) + dmap"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center><img src=\"https://assets.holoviews.org/gifs/examples/streams/bokeh/boundsx_selection.gif\"></center>"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
