{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This demo uses VoilĂ  to render a notebook to a custom HTML page using gridstack.js for the layout of each output. In the cell metadata you can change the default cell with and height (in grid units between 1 and 12) by specifying.\n", " * `grid_row`\n", " * `grid_columns`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "n = 200\n", "\n", "x = np.linspace(0.0, 10.0, n)\n", "y = np.cumsum(np.random.randn(n)*10).astype(int)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipywidgets as widgets" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "label_selected = widgets.Label(value=\"Selected: 0\")\n", "label_selected" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "grid_columns": 8, "grid_rows": 4 }, "outputs": [], "source": [ "import numpy as np\n", "from bqplot import pyplot as plt\n", "import bqplot\n", "\n", "fig = plt.figure( title='Histogram')\n", "np.random.seed(0)\n", "hist = plt.hist(y, bins=25)\n", "hist.scales['sample'].min = float(y.min())\n", "hist.scales['sample'].max = float(y.max())\n", "display(fig)\n", "fig.layout.width = 'auto'\n", "fig.layout.height = 'auto'\n", "fig.layout.min_height = '300px' # so it shows nicely in the notebook\n", "fig.layout.flex = '1'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "grid_columns": 12, "grid_rows": 6 }, "outputs": [], "source": [ "import numpy as np\n", "from bqplot import pyplot as plt\n", "import bqplot\n", "\n", "fig = plt.figure( title='Line Chart')\n", "np.random.seed(0)\n", "n = 200\n", "p = plt.plot(x, y)\n", "fig" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig.layout.width = 'auto'\n", "fig.layout.height = 'auto'\n", "fig.layout.min_height = '300px' # so it shows nicely in the notebook\n", "fig.layout.flex = '1'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "brushintsel = bqplot.interacts.BrushIntervalSelector(scale=p.scales['x'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def update_range(*args):\n", " label_selected.value = \"Selected range {}\".format(brushintsel.selected)\n", " mask = (x > brushintsel.selected[0]) & (x < brushintsel.selected[1])\n", " hist.sample = y[mask]\n", " \n", "brushintsel.observe(update_range, 'selected')\n", "fig.interaction = brushintsel" ] } ], "metadata": { "celltoolbar": "Edit Metadata", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }