203 lines
4.7 KiB
Plaintext
203 lines
4.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"This demo uses Voilà to render a notebook to a custom HTML page using gridstack.js for the layout of each output. In the cell metadata you can change the default cell with and height (in grid units between 1 and 12) by specifying.\n",
|
|
" * `grid_row`\n",
|
|
" * `grid_columns`"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import numpy as np\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"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import ipywidgets as widgets"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "fb68ca2d6f7f40c2adb9d01d134a4373",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"Label(value='Selected: 0')"
|
|
]
|
|
},
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"label_selected = widgets.Label(value=\"Selected: 0\")\n",
|
|
"label_selected"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"grid_columns": 8,
|
|
"grid_rows": 4
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "227e65a70eab4eb38b0b2f25d8237656",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale(max=70.0, min=-131.0))]…"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"from bqplot import pyplot as plt\n",
|
|
"import bqplot\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",
|
|
"display(fig)\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.layout.flex = '1'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {
|
|
"grid_columns": 12,
|
|
"grid_rows": 6
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "5fee6ee9af0a4dc7a557f8d16a5b7150",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…"
|
|
]
|
|
},
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"from bqplot import pyplot as plt\n",
|
|
"import bqplot\n",
|
|
"\n",
|
|
"fig = plt.figure( title='Line Chart')\n",
|
|
"np.random.seed(0)\n",
|
|
"n = 200\n",
|
|
"p = plt.plot(x, y)\n",
|
|
"fig"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig.layout.width = 'auto'\n",
|
|
"fig.layout.height = 'auto'\n",
|
|
"fig.layout.min_height = '300px' # so it shows nicely in the notebook\n",
|
|
"fig.layout.flex = '1'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"brushintsel = bqplot.interacts.BrushIntervalSelector(scale=p.scales['x'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def update_range(*args):\n",
|
|
" label_selected.value = \"Selected range {}\".format(brushintsel.selected)\n",
|
|
" mask = (x > brushintsel.selected[0]) & (x < brushintsel.selected[1])\n",
|
|
" hist.sample = y[mask]\n",
|
|
" \n",
|
|
"brushintsel.observe(update_range, 'selected')\n",
|
|
"fig.interaction = brushintsel"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"celltoolbar": "Edit Metadata",
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.10.8"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|