{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#### **Title**: Point Selection1D stream example\n", "\n", "**Description**: A linked streams example demonstrating how to use Selection1D to get currently selected points and dynamically compute statistics of selection.\n", "\n", "**Dependencies**: Plotly\n", "\n", "**Backends**: [Plotly](./Selection1D_points.ipynb), [Bokeh](../bokeh/Selection1D_points.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import holoviews as hv\n", "from holoviews import streams\n", "hv.extension('plotly')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Declare some points\n", "points = hv.Points(np.random.randn(1000,2 ))\n", "\n", "# Declare points as source of selection stream\n", "selection = streams.Selection1D(source=points)\n", "\n", "# Write function that uses the selection indices to slice points and compute stats\n", "def selected_info(index):\n", " selected = points.iloc[index]\n", " if index:\n", " label = 'Mean x, y: %.3f, %.3f' % tuple(selected.array().mean(axis=0))\n", " else:\n", " label = 'No selection'\n", " return selected.relabel(label).opts(color='red')\n", "\n", "# Combine points and DynamicMap\n", "points + hv.DynamicMap(selected_info, streams=[selection])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }