{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Most examples work across multiple plotting backends, this example is also available for:\n",
    "\n",
    "* [Matplotlib - mandelbrot section](../matplotlib/mandelbrot_section.ipynb)\n",
    "\n",
    "HoloViews demo that used to be showcased on the [holoviews.org"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import holoviews as hv\n",
    "hv.extension('bokeh')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import io\n",
    "try:    from urllib2 import urlopen\n",
    "except: from urllib.request import urlopen\n",
    "\n",
    "raw = urlopen('http://assets.holoviews.org/data/mandelbrot.npy').read()\n",
    "array = np.load(io.BytesIO(raw)).astype(np.float32)[::4,::4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%opts Points [scaling_factor=50] Contours [show_legend=False] (color='w')\n",
    "dots = np.linspace(-0.45, 0.45, 19)\n",
    "fractal = hv.Image(array)\n",
    "# First example on the old holoviews.org homepage was:\n",
    "# ((fractal * hv.HLine(y=0)).hist() + fractal.sample(y=0))\n",
    "layouts = {y: (fractal * hv.Points(fractal.sample([(i,y) for i in dots])) +\n",
    "               fractal.sample(y=y) +\n",
    "               hv.operation.threshold(fractal, level=np.percentile(fractal.sample(y=y)['z'], 90)) +\n",
    "               hv.operation.contours(fractal, levels=[np.percentile(fractal.sample(y=y)['z'], 60)]))\n",
    "            for y in np.linspace(-0.3, 0.3, 11)} # Half the frames of the bokeh version\n",
    "\n",
    "hv.HoloMap(layouts, kdims='Y').collate().cols(2)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
