Skip to content

Commit 4586854

Browse files
committed
Add bqplot example
1 parent acc0674 commit 4586854

File tree

3 files changed

+212
-9
lines changed

3 files changed

+212
-9
lines changed

docs/bqplot.ipynb

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
}

docs/index.rst

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
jupyterlite-sphinx
22
==================
33

4-
Installation:
5-
-------------
4+
Installation
5+
------------
66

77
You can install ``jupyterlite-sphinx`` with ``pip``:
88

@@ -20,8 +20,8 @@ then you need to add the ``jupyterlite-sphinx`` extension to your ``conf.py`` fi
2020
# ...
2121
]
2222
23-
Replite directive:
24-
------------------
23+
Replite directive
24+
-----------------
2525

2626
``jupyterlite-sphinx`` provides a ``replite`` directive that allows you to embed a replite console in your docs.
2727
This directive takes the same options as the ``replite`` package, see https://github.com/jtpio/replite for reference.
@@ -46,8 +46,8 @@ This directive takes the same options as the ``replite`` package, see https://gi
4646

4747
print('Hello, World!')
4848

49-
Retrolite directive:
50-
--------------------
49+
Retrolite directive
50+
-------------------
5151

5252
``jupyterlite-sphinx`` provides a ``retrolite`` directive that allows you to embed an entire executable Notebook in your docs.
5353
It takes the name of the Notebook as argument:
@@ -58,11 +58,47 @@ It takes the name of the Notebook as argument:
5858
5959
.. retrolite:: my_notebook.ipynb
6060

61-
JupyterLab and RetroLab deployed for you:
62-
-----------------------------------------
61+
JupyterLab and RetroLab deployed for you
62+
----------------------------------------
6363

6464
``jupyterlite-sphinx`` makes a full deployment of JupyterLite for you, you can access the JupyterLab UI and RetroLab UI following the
6565
``./lite/lab/index.html`` and ``./lite/retro/index.html`` relative URLs:
6666

6767
`JupyterLab <./lite/lab/index.html>`_
6868
`Retrolab <./lite/retro/index.html>`_
69+
70+
Configuration
71+
-------------
72+
73+
You can provide custom configuration to your JupyterLite deployment.
74+
75+
For example, if you want to have bqplot working in this deployment, you need to install the bqplot federated extension
76+
and you can serve the bqplot wheel to ``piplite``, this is done by telling your ``conf.py`` where to look for the jupyterlite config:
77+
78+
.. code-block:: python
79+
80+
jupyterlite_config = "jupyterlite_config.json"
81+
82+
The ``jupyterlite_config.json`` containing the following:
83+
84+
.. code-block:: json
85+
86+
{
87+
"LiteBuildConfig": {
88+
"federated_extensions": [
89+
"https://github.com/conda-forge/releases/releases/download/noarch/bqplot-0.12.33-pyhd8ed1ab_0.tar.bz2/bqplot-0.12.33-pyhd8ed1ab_0.tar.bz2",
90+
],
91+
"ignore_sys_prefix": true,
92+
"piplite_urls": [
93+
"https://files.pythonhosted.org/packages/py2.py3/b/bqplot/bqplot-0.12.33-py2.py3-none-any.whl",
94+
]
95+
}
96+
}
97+
98+
Then you should be able to show Notebooks working with bqplot!
99+
100+
.. code-block:: rst
101+
102+
.. retrolite:: bqplot.ipynb
103+
104+
.. retrolite:: bqplot.ipynb

docs/jupyterlite_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@
8282
"https://files.pythonhosted.org/packages/py3/x/xyzservices/xyzservices-2022.2.0-py3-none-any.whl"
8383
]
8484
}
85-
}
85+
}

0 commit comments

Comments
 (0)