{ "cells": [ { "cell_type": "markdown", "source": [ "# `bqplot` Interactive Demo\n", "\n", "Plotting in JupyterLite\n", "\n", "`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." ], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "import piplite\n", "\n", "await piplite.install('bqplot')" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "from bqplot import *\n", "\n", "import numpy as np\n", "import pandas as pd\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.\n", "\n", "sc_x = LinearScale()\n", "sc_y = LinearScale()\n", "\n", "lines = Lines(\n", " x=x, y=y,\n", " scales={'x': sc_x, 'y': sc_y}\n", ")\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')" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "lines.colors = ['green']" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "lines.fill = 'bottom'" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "lines.marker = 'circle'" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "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(\n", " x=x, y=y,\n", " scales={'x': sc_x, 'y': sc_y}\n", ")\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)" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "bars.y = np.cumsum(np.random.randn(n))" ], "outputs": [], "metadata": {} }, { "cell_type": "markdown", "source": [ "### Plots which use Nested Buffers" ], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "from bqplot import *\n", "\n", "import numpy as np\n", "import pandas as pd\n", "\n", "np.random.seed(0)\n", "y1 = np.cumsum(np.random.randn(150)) + 100.\n", "y2 = np.cumsum(np.random.randn(150)) + 100.\n", "y3 = np.cumsum(np.random.randn(150)) + 100.\n", "y4 = np.cumsum(np.random.randn(150)) + 100.\n", "\n", "sc_x = LinearScale()\n", "sc_y = LinearScale()\n", "\n", "lines = Lines(x=np.arange(len(y1)), y=[y1, y2, y3, y4],\n", " 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')" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [], "outputs": [], "metadata": {} } ], "metadata": { "orig_nbformat": 4, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }