{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `bqplot` Interactive Demo\n", "\n", "Plotting in JupyterLite\n", "\n", "`bqplot` can be installed in this deployment (it provides the bqplot federated\n", "extension), but you will need to make your own deployment to have access to other\n", "interactive widgets libraries." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install -q bqplot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from bqplot import *\n", "\n", "np.random.seed(0)\n", "\n", "n = 100\n", "\n", "x = list(range(n))\n", "y = np.cumsum(np.random.randn(n)) + 100.0\n", "\n", "sc_x = LinearScale()\n", "sc_y = LinearScale()\n", "\n", "lines = Lines(x=x, y=y, scales={\"x\": sc_x, \"y\": sc_y})\n", "ax_x = Axis(scale=sc_x, label=\"Index\")\n", "ax_y = Axis(scale=sc_y, orientation=\"vertical\", label=\"lines\")\n", "\n", "Figure(marks=[lines], axes=[ax_x, ax_y], title=\"Lines\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lines.colors = [\"green\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lines.fill = \"bottom\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lines.marker = \"circle\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 100\n", "\n", "x = list(range(n))\n", "y = np.cumsum(np.random.randn(n))\n", "\n", "sc_x = LinearScale()\n", "sc_y = LinearScale()\n", "\n", "bars = Bars(x=x, y=y, scales={\"x\": sc_x, \"y\": sc_y})\n", "ax_x = Axis(scale=sc_x, label=\"Index\")\n", "ax_y = Axis(scale=sc_y, orientation=\"vertical\", label=\"bars\")\n", "\n", "Figure(marks=[bars], axes=[ax_x, ax_y], title=\"Bars\", animation_duration=1000)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars.y = np.cumsum(np.random.randn(n))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plots which use Nested Buffers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from bqplot import *\n", "\n", "np.random.seed(0)\n", "y1 = np.cumsum(np.random.randn(150)) + 100.0\n", "y2 = np.cumsum(np.random.randn(150)) + 100.0\n", "y3 = np.cumsum(np.random.randn(150)) + 100.0\n", "y4 = np.cumsum(np.random.randn(150)) + 100.0\n", "\n", "sc_x = LinearScale()\n", "sc_y = LinearScale()\n", "\n", "lines = Lines(x=np.arange(len(y1)), y=[y1, y2, y3, y4], scales={\"x\": sc_x, \"y\": sc_y})\n", "ax_x = Axis(scale=sc_x, label=\"Index\")\n", "ax_y = Axis(scale=sc_y, orientation=\"vertical\", label=\"lines\")\n", "\n", "Figure(marks=[lines], axes=[ax_x, ax_y], title=\"Lines\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }