|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "source": [ |
| 6 | + "# `bqplot` Interactive Demo\n", |
| 7 | + "\n", |
| 8 | + "Plotting in JupyterLite\n", |
| 9 | + "\n", |
| 10 | + "`bqplot` can be installed in this deployment (it provides the bqplot federated extension), but you will need to make your own deployment to have access to other interactive widgets libraries." |
| 11 | + ], |
| 12 | + "metadata": {} |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": null, |
| 17 | + "source": [ |
| 18 | + "import piplite\n", |
| 19 | + "\n", |
| 20 | + "await piplite.install('bqplot')" |
| 21 | + ], |
| 22 | + "outputs": [], |
| 23 | + "metadata": {} |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "code", |
| 27 | + "execution_count": null, |
| 28 | + "source": [ |
| 29 | + "from bqplot import *\n", |
| 30 | + "\n", |
| 31 | + "import numpy as np\n", |
| 32 | + "import pandas as pd\n", |
| 33 | + "\n", |
| 34 | + "np.random.seed(0)\n", |
| 35 | + "\n", |
| 36 | + "n = 100\n", |
| 37 | + "\n", |
| 38 | + "x = list(range(n))\n", |
| 39 | + "y = np.cumsum(np.random.randn(n)) + 100.\n", |
| 40 | + "\n", |
| 41 | + "sc_x = LinearScale()\n", |
| 42 | + "sc_y = LinearScale()\n", |
| 43 | + "\n", |
| 44 | + "lines = Lines(\n", |
| 45 | + " x=x, y=y,\n", |
| 46 | + " scales={'x': sc_x, 'y': sc_y}\n", |
| 47 | + ")\n", |
| 48 | + "ax_x = Axis(scale=sc_x, label='Index')\n", |
| 49 | + "ax_y = Axis(scale=sc_y, orientation='vertical', label='lines')\n", |
| 50 | + "\n", |
| 51 | + "Figure(marks=[lines], axes=[ax_x, ax_y], title='Lines')" |
| 52 | + ], |
| 53 | + "outputs": [], |
| 54 | + "metadata": {} |
| 55 | + }, |
| 56 | + { |
| 57 | + "cell_type": "code", |
| 58 | + "execution_count": null, |
| 59 | + "source": [ |
| 60 | + "lines.colors = ['green']" |
| 61 | + ], |
| 62 | + "outputs": [], |
| 63 | + "metadata": {} |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "code", |
| 67 | + "execution_count": null, |
| 68 | + "source": [ |
| 69 | + "lines.fill = 'bottom'" |
| 70 | + ], |
| 71 | + "outputs": [], |
| 72 | + "metadata": {} |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "execution_count": null, |
| 77 | + "source": [ |
| 78 | + "lines.marker = 'circle'" |
| 79 | + ], |
| 80 | + "outputs": [], |
| 81 | + "metadata": {} |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "code", |
| 85 | + "execution_count": null, |
| 86 | + "source": [ |
| 87 | + "n = 100\n", |
| 88 | + "\n", |
| 89 | + "x = list(range(n))\n", |
| 90 | + "y = np.cumsum(np.random.randn(n))\n", |
| 91 | + "\n", |
| 92 | + "sc_x = LinearScale()\n", |
| 93 | + "sc_y = LinearScale()\n", |
| 94 | + "\n", |
| 95 | + "bars = Bars(\n", |
| 96 | + " x=x, y=y,\n", |
| 97 | + " scales={'x': sc_x, 'y': sc_y}\n", |
| 98 | + ")\n", |
| 99 | + "ax_x = Axis(scale=sc_x, label='Index')\n", |
| 100 | + "ax_y = Axis(scale=sc_y, orientation='vertical', label='bars')\n", |
| 101 | + "\n", |
| 102 | + "Figure(marks=[bars], axes=[ax_x, ax_y], title='Bars', animation_duration=1000)" |
| 103 | + ], |
| 104 | + "outputs": [], |
| 105 | + "metadata": {} |
| 106 | + }, |
| 107 | + { |
| 108 | + "cell_type": "code", |
| 109 | + "execution_count": null, |
| 110 | + "source": [ |
| 111 | + "bars.y = np.cumsum(np.random.randn(n))" |
| 112 | + ], |
| 113 | + "outputs": [], |
| 114 | + "metadata": {} |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "markdown", |
| 118 | + "source": [ |
| 119 | + "### Plots which use Nested Buffers" |
| 120 | + ], |
| 121 | + "metadata": {} |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "code", |
| 125 | + "execution_count": null, |
| 126 | + "source": [ |
| 127 | + "from bqplot import *\n", |
| 128 | + "\n", |
| 129 | + "import numpy as np\n", |
| 130 | + "import pandas as pd\n", |
| 131 | + "\n", |
| 132 | + "np.random.seed(0)\n", |
| 133 | + "y1 = np.cumsum(np.random.randn(150)) + 100.\n", |
| 134 | + "y2 = np.cumsum(np.random.randn(150)) + 100.\n", |
| 135 | + "y3 = np.cumsum(np.random.randn(150)) + 100.\n", |
| 136 | + "y4 = np.cumsum(np.random.randn(150)) + 100.\n", |
| 137 | + "\n", |
| 138 | + "sc_x = LinearScale()\n", |
| 139 | + "sc_y = LinearScale()\n", |
| 140 | + "\n", |
| 141 | + "lines = Lines(x=np.arange(len(y1)), y=[y1, y2, y3, y4],\n", |
| 142 | + " scales={'x': sc_x, 'y': sc_y})\n", |
| 143 | + "ax_x = Axis(scale=sc_x, label='Index')\n", |
| 144 | + "ax_y = Axis(scale=sc_y, orientation='vertical', label='lines')\n", |
| 145 | + "\n", |
| 146 | + "Figure(marks=[lines], axes=[ax_x, ax_y], title='Lines')" |
| 147 | + ], |
| 148 | + "outputs": [], |
| 149 | + "metadata": {} |
| 150 | + }, |
| 151 | + { |
| 152 | + "cell_type": "code", |
| 153 | + "execution_count": null, |
| 154 | + "source": [], |
| 155 | + "outputs": [], |
| 156 | + "metadata": {} |
| 157 | + } |
| 158 | + ], |
| 159 | + "metadata": { |
| 160 | + "orig_nbformat": 4, |
| 161 | + "language_info": { |
| 162 | + "name": "python" |
| 163 | + } |
| 164 | + }, |
| 165 | + "nbformat": 4, |
| 166 | + "nbformat_minor": 2 |
| 167 | +} |
0 commit comments