|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": { |
| 7 | + "ExecuteTime": { |
| 8 | + "end_time": "2020-06-30T14:44:37.710652Z", |
| 9 | + "start_time": "2020-06-30T14:44:36.873479Z" |
| 10 | + } |
| 11 | + }, |
| 12 | + "outputs": [], |
| 13 | + "source": [ |
| 14 | + "from bqplot import pyplot as plt\n", |
| 15 | + "import ipywidgets as widgets\n", |
| 16 | + "import numpy as np" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": null, |
| 22 | + "metadata": { |
| 23 | + "ExecuteTime": { |
| 24 | + "end_time": "2020-06-30T14:44:37.783189Z", |
| 25 | + "start_time": "2020-06-30T14:44:37.771507Z" |
| 26 | + } |
| 27 | + }, |
| 28 | + "outputs": [], |
| 29 | + "source": [ |
| 30 | + "# generate some fake \n", |
| 31 | + "n = 2000\n", |
| 32 | + "x = np.linspace(0.0, 10.0, n)\n", |
| 33 | + "np.random.seed(0)\n", |
| 34 | + "y = np.cumsum(np.random.randn(n)*10).astype(int)" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "code", |
| 39 | + "execution_count": null, |
| 40 | + "metadata": { |
| 41 | + "ExecuteTime": { |
| 42 | + "end_time": "2020-06-30T14:44:37.916067Z", |
| 43 | + "start_time": "2020-06-30T14:44:37.789416Z" |
| 44 | + } |
| 45 | + }, |
| 46 | + "outputs": [], |
| 47 | + "source": [ |
| 48 | + "fig_hist = plt.figure( title='Histogram in Voila')\n", |
| 49 | + "hist = plt.hist(y, bins=25, colors=['steelblue'])\n", |
| 50 | + "fig_hist" |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": null, |
| 56 | + "metadata": { |
| 57 | + "ExecuteTime": { |
| 58 | + "end_time": "2020-06-30T14:44:39.324769Z", |
| 59 | + "start_time": "2020-06-30T14:44:39.302431Z" |
| 60 | + } |
| 61 | + }, |
| 62 | + "outputs": [], |
| 63 | + "source": [ |
| 64 | + "hist.bins = 10;" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": null, |
| 70 | + "metadata": { |
| 71 | + "ExecuteTime": { |
| 72 | + "end_time": "2020-06-30T14:44:39.967211Z", |
| 73 | + "start_time": "2020-06-30T14:44:39.947076Z" |
| 74 | + } |
| 75 | + }, |
| 76 | + "outputs": [], |
| 77 | + "source": [ |
| 78 | + "slider = widgets.IntSlider(min=1, max=100, v_model=30)\n", |
| 79 | + "slider" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": null, |
| 85 | + "metadata": { |
| 86 | + "ExecuteTime": { |
| 87 | + "end_time": "2020-06-30T14:44:41.005101Z", |
| 88 | + "start_time": "2020-06-30T14:44:40.998667Z" |
| 89 | + } |
| 90 | + }, |
| 91 | + "outputs": [], |
| 92 | + "source": [ |
| 93 | + "slider.value = 20;" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": null, |
| 99 | + "metadata": { |
| 100 | + "ExecuteTime": { |
| 101 | + "end_time": "2020-06-30T14:44:41.678387Z", |
| 102 | + "start_time": "2020-06-30T14:44:41.667654Z" |
| 103 | + } |
| 104 | + }, |
| 105 | + "outputs": [], |
| 106 | + "source": [ |
| 107 | + "widgets.link((hist, 'bins'), (slider, 'value'));" |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "execution_count": null, |
| 113 | + "metadata": { |
| 114 | + "ExecuteTime": { |
| 115 | + "end_time": "2020-06-30T14:44:42.384650Z", |
| 116 | + "start_time": "2020-06-30T14:44:42.280810Z" |
| 117 | + } |
| 118 | + }, |
| 119 | + "outputs": [], |
| 120 | + "source": [ |
| 121 | + "fig_lines = plt.figure( title='Line Chart')\n", |
| 122 | + "lines = plt.plot(x, y)\n", |
| 123 | + "fig_lines" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": null, |
| 129 | + "metadata": { |
| 130 | + "ExecuteTime": { |
| 131 | + "end_time": "2020-06-30T14:44:43.494747Z", |
| 132 | + "start_time": "2020-06-30T14:44:43.473428Z" |
| 133 | + } |
| 134 | + }, |
| 135 | + "outputs": [], |
| 136 | + "source": [ |
| 137 | + "selector = plt.brush_int_selector()\n", |
| 138 | + "def update_range(*ignore):\n", |
| 139 | + " if selector.selected is not None and len(selector.selected) == 2:\n", |
| 140 | + " xmin, xmax = selector.selected\n", |
| 141 | + " mask = (x > xmin) & (x < xmax)\n", |
| 142 | + " hist.sample = y[mask]\n", |
| 143 | + "selector.observe(update_range, 'selected') " |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "cell_type": "code", |
| 148 | + "execution_count": null, |
| 149 | + "metadata": {}, |
| 150 | + "outputs": [], |
| 151 | + "source": [] |
| 152 | + } |
| 153 | + ], |
| 154 | + "metadata": { |
| 155 | + "kernelspec": { |
| 156 | + "display_name": "Python 3", |
| 157 | + "language": "python", |
| 158 | + "name": "python3" |
| 159 | + }, |
| 160 | + "language_info": { |
| 161 | + "codemirror_mode": { |
| 162 | + "name": "ipython", |
| 163 | + "version": 3 |
| 164 | + }, |
| 165 | + "file_extension": ".py", |
| 166 | + "mimetype": "text/x-python", |
| 167 | + "name": "python", |
| 168 | + "nbconvert_exporter": "python", |
| 169 | + "pygments_lexer": "ipython3", |
| 170 | + "version": "3.8.3" |
| 171 | + }, |
| 172 | + "widgets": { |
| 173 | + "application/vnd.jupyter.widget-state+json": { |
| 174 | + "state": {}, |
| 175 | + "version_major": 2, |
| 176 | + "version_minor": 0 |
| 177 | + } |
| 178 | + } |
| 179 | + }, |
| 180 | + "nbformat": 4, |
| 181 | + "nbformat_minor": 4 |
| 182 | +} |
0 commit comments