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/elements/plotly/Box.ipynb
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### **Title**: Box Element\n",
    "\n",
    "**Dependencies**: Plotly\n",
    "\n",
    "**Backends**: [Bokeh](../bokeh/Box.ipynb), [Matplotlib](../matplotlib/Box.ipynb), [Plotly](./Box.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('plotly')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A ``Box`` is an annotation that takes a center x-position, a center y-position and a size:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = np.sin(np.mgrid[0:100,0:100][1]/10.0)\n",
    "data[np.arange(40, 60), np.arange(20, 40)] = -1\n",
    "data[np.arange(40, 50), np.arange(70, 80)] = -3    \n",
    "example = hv.Image(data) * hv.Box(-0.2, 0, 0.25 ) * hv.Box(-0, 0, (0.4,0.9) )\n",
    "example.opts(\n",
    "    opts.Box(line_color='red', line_width=5), \n",
    "    opts.Image(cmap='gray'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In addition to these arguments, it supports an optional ``aspect ratio``:\n",
    "\n",
    "By default, the size argument results in a square such as the small square shown above. Alternatively, the size can be given as the tuple ``(width, height)`` resulting in a rectangle. If you only supply a size value, you can still specify a rectangle by specifying an optional aspect value. In addition, you can also set the orientation (in radians, rotating anticlockwise):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = np.sin(np.mgrid[0:100,0:100][1]/10.0)\n",
    "data[np.arange(30, 70), np.arange(30, 70)] = -3\n",
    "example = hv.Image(data) * hv.Box(-0, 0, 0.25, aspect=3, orientation=-np.pi/4)\n",
    "example.opts(\n",
    "    opts.Box(line_color='purple', line_width=5), \n",
    "    opts.Image(cmap='gray'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For full documentation and the available style and plot options, use ``hv.help(hv.Box).``"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}