{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#### **Title**: Multiple selection streams example\n", "\n", "**Description**: A linked streams example demonstrating how to use multiple Selection1D streams on separate Points objects.\n", "\n", "**Dependencies**: Bokeh\n", "\n", "**Backends**: [Bokeh](./Selection1D_paired.ipynb), [Plotly](../plotly/Selection1D_paired.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import holoviews as hv\n", "from holoviews import opts, streams\n", "\n", "hv.extension('bokeh')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Declare two sets of points generated from multivariate distribution\n", "points = hv.Points(np.random.multivariate_normal((0, 0), [[1, 0.1], [0.1, 1]], (1000,)))\n", "points2 = hv.Points(np.random.multivariate_normal((3, 3), [[1, 0.1], [0.1, 1]], (1000,)))\n", "\n", "# Declare two selection streams and set points and points2 as the source of each\n", "sel1 = streams.Selection1D(source=points)\n", "sel2 = streams.Selection1D(source=points2)\n", "\n", "# Declare DynamicMaps to show mean y-value of selection as HLine\n", "hline1 = hv.DynamicMap(lambda index: hv.HLine(points['y'][index].mean() if index else -10), streams=[sel1])\n", "hline2 = hv.DynamicMap(lambda index: hv.HLine(points2['y'][index].mean() if index else -10), streams=[sel2])\n", "\n", "# Combine points and dynamic HLines\n", "(points * points2 * hline1 * hline2).opts(\n", " opts.Points(active_tools=['box_select', 'tap'], height=400,\n", " tools=['box_select', 'lasso_select', 'tap'], width=400))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }