{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "
Title
Simple pointer example
\n", "
Description
A linked streams example demonstrating how us a PointerXY stream to reveal more information about coordinate.
\n", "
Backends
Bokeh
\n", "
Tags
streams, linked, pointer, interactive
\n", "
\n", "
" ] }, { "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('bokeh')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Y,X=(np.mgrid[0:100, 0:100]-50.)/20.\n", "img = hv.Image(np.sin(X**2+Y**2))\n", "\n", "# Declare pointer stream initializing at (0, 0) and linking to Image\n", "pointer = streams.PointerXY(x=0, y=0, source=img)\n", "\n", "# Define function to draw cross-hair and report value of image at location as text\n", "def cross_hair_info(x, y):\n", " text = hv.Text(x+0.05, y, '%.3f'% img[x,y], halign='left', valign='bottom')\n", " return hv.HLine(y) * hv.VLine(x) * text\n", "\n", "# Overlay image and cross_hair_info\n", "img * hv.DynamicMap(cross_hair_info, streams=[pointer])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }