{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipyvuetify as v" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# First histogram plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipywidgets as widgets\n", "import numpy as np\n", "from bqplot import pyplot as plt\n", "import bqplot\n", "\n", "\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", "\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", "fig.layout.width = 'auto'\n", "fig.layout.height = 'auto'\n", "fig.layout.min_height = '300px' # so it shows nicely in the notebook\n", "fig" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "slider = v.Slider(thumb_label='always', class_=\"px-4\", v_model=30)\n", "widgets.link((slider, 'v_model'), (hist, 'bins'))\n", "slider" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Line chart" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig2 = plt.figure( title='Line Chart')\n", "np.random.seed(0)\n", "p = plt.plot(x, y)\n", "\n", "fig2.layout.width = 'auto'\n", "fig2.layout.height = 'auto'\n", "fig2.layout.min_height = '300px' # so it shows nicely in the notebook\n", "fig2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "brushintsel = bqplot.interacts.BrushIntervalSelector(scale=p.scales['x'])\n", "\n", "def update_range(*args):\n", " if brushintsel.selected is not None and brushintsel.selected.shape == (2,):\n", " mask = (x > brushintsel.selected[0]) & (x < brushintsel.selected[1])\n", " hist.sample = y[mask]\n", " \n", "brushintsel.observe(update_range, 'selected')\n", "fig2.interaction = brushintsel" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Second histogram plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n2 = 200\n", "\n", "x2 = np.linspace(0.0, 10.0, n)\n", "y2 = np.cumsum(np.random.randn(n)*10).astype(int)\n", "\n", "figHist2 = plt.figure( title='Histogram 2')\n", "np.random.seed(0)\n", "hist2 = plt.hist(y2, bins=25)\n", "hist2.scales['sample'].min = float(y2.min())\n", "hist2.scales['sample'].max = float(y2.max())\n", "figHist2.layout.width = 'auto'\n", "figHist2.layout.height = 'auto'\n", "figHist2.layout.min_height = '300px' # so it shows nicely in the notebook\n", "\n", "sliderHist2 = v.Slider(_metadata={'mount_id': 'histogram_bins2'}, thumb_label='always', class_='px-4', v_model=5)\n", "from traitlets import link\n", "link((sliderHist2, 'v_model'), (hist2, 'bins'))\n", "\n", "\n", "display(figHist2)\n", "display(sliderHist2)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Set up voila vuetify layout\n", "The voila vuetify template does not render output from the notebook, it only shows widget with the mount_id metadata." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "v.Tabs(_metadata={'mount_id': 'content-main'}, children=[\n", " v.Tab(children=['Tab1']),\n", " v.Tab(children=['Tab2']),\n", " v.TabItem(children=[\n", " v.Layout(row=True, wrap=True, align_center=True, children=[\n", " v.Flex(xs12=True, lg6=True, xl4=True, children=[\n", " fig, slider\n", " ]),\n", " v.Flex(xs12=True, lg6=True, xl4=True, children=[\n", " figHist2, sliderHist2\n", " ]),\n", " v.Flex(xs12=True, xl4=True, children=[\n", " fig2\n", " ]),\n", " ])\n", " ]),\n", " v.TabItem(children=[\n", " v.Container(children=['Lorum ipsum'])\n", " ])\n", "])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7" }, "voila": { "template": "vuetify-default" } }, "nbformat": 4, "nbformat_minor": 2 }