HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/anaconda3/Lib/site-packages/holoviews/examples/reference/streams/bokeh/PointerX.ipynb
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### **Title**: Linked pointer cross-section example\n",
    "\n",
    "**Description**: A linked streams example demonstrating how to use PointerXY stream linked across two plots.\n",
    "\n",
    "**Dependencies**: Bokeh\n",
    "\n",
    "**Backends**: [Bokeh](./PointerX.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import holoviews as hv\n",
    "from holoviews import opts\n",
    "hv.extension('bokeh')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "opts.defaults(opts.Curve(width=100))\n",
    "\n",
    "# Create two images\n",
    "x,y = np.meshgrid(np.linspace(-5,5,101), np.linspace(5,-5,101))\n",
    "img1 = hv.Image(np.sin(x**2+y**2))\n",
    "img2 = hv.Image(np.sin(x**2+y**3))\n",
    "\n",
    "# Declare PointerX and dynamic VLine\n",
    "posx = hv.streams.PointerX(x=0)\n",
    "vline = hv.DynamicMap(lambda x: hv.VLine(x or -100), streams=[posx])\n",
    "\n",
    "# Declare cross-sections at PointerX location\n",
    "# Using apply syntax\n",
    "crosssection1 = img1.apply.sample(x=posx.param.x)\n",
    "# By constructing a DynamicMap\n",
    "crosssection2 = hv.DynamicMap(lambda x: img2.sample(x=x if x else 0), streams=[posx])\n",
    "\n",
    "# Combine images, vline and cross-sections\n",
    "((img1 * vline) << crosssection1) + ((img2 * vline) << crosssection2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center><img src=\"https://assets.holoviews.org/gifs/examples/streams/bokeh/linked_pointer_crosssection.gif\" width=600></center>"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}