Skip to content

Commit 06407ae

Browse files
committed
update ipympl in other libraries section
1 parent 7f2e8da commit 06407ae

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

notebooks/07.More-libraries/07.05-other-widget-libraries.ipynb

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@
276276
"source": [
277277
"# ipympl: The Matplotlib Jupyter Widget Backend\n",
278278
"\n",
279-
"## https://github.com/matplotlib/ipympl\n",
279+
"## https://matplotlib.org/ipympl/\n",
280280
"\n",
281281
"\n",
282282
"Enabling interaction with matplotlib charts in the Jupyter notebook and JupyterLab\n",
@@ -295,7 +295,7 @@
295295
"id": "91a33e30-803d-4945-8129-2c37f30a1d09",
296296
"metadata": {},
297297
"source": [
298-
"Enabling the `widget` backend. This requires ipympl. ipympl can be install via pip or conda."
298+
"Enabling the `ipympl` (sometimes written `widget`) backend. ipympl can be install via pip or conda."
299299
]
300300
},
301301
{
@@ -305,7 +305,7 @@
305305
"metadata": {},
306306
"outputs": [],
307307
"source": [
308-
"%matplotlib widget"
308+
"%matplotlib ipympl"
309309
]
310310
},
311311
{
@@ -334,32 +334,30 @@
334334
"cell_type": "code",
335335
"execution_count": null,
336336
"id": "9db5b3e0-317c-4b79-bb5c-36786d02895a",
337-
"metadata": {},
337+
"metadata": {
338+
"tags": []
339+
},
338340
"outputs": [],
339341
"source": [
340-
"plt.ioff()\n",
341-
"plt.clf()\n",
342-
"\n",
343-
"slider = FloatSlider(\n",
344-
" value=1.0,\n",
345-
" min=0.02,\n",
346-
" max=2.0\n",
347-
")\n",
348-
"\n",
349-
"fig1 = plt.figure(1)\n",
342+
"with plt.ioff():\n",
343+
" fig, ax = plt.subplots()\n",
350344
"\n",
351345
"x1 = np.linspace(0, 20, 500)\n",
352346
"\n",
353347
"lines = plt.plot(x1, np.sin(slider.value * x1))\n",
354348
"\n",
355349
"def update_lines(change):\n",
356350
" lines[0].set_data(x1, np.sin(change.new * x1))\n",
357-
" fig1.canvas.draw()\n",
358-
" fig1.canvas.flush_events()\n",
351+
" fig.canvas.draw()\n",
359352
"\n",
353+
"slider = FloatSlider(\n",
354+
" value=1.0,\n",
355+
" min=0.02,\n",
356+
" max=2.0\n",
357+
")\n",
360358
"slider.observe(update_lines, names='value')\n",
361359
"\n",
362-
"VBox([slider, fig1.canvas])"
360+
"VBox([slider, fig.canvas])"
363361
]
364362
},
365363
{
@@ -451,6 +449,13 @@
451449
"nbconvert_exporter": "python",
452450
"pygments_lexer": "ipython3",
453451
"version": "3.9.13"
452+
},
453+
"widgets": {
454+
"application/vnd.jupyter.widget-state+json": {
455+
"state": {},
456+
"version_major": 2,
457+
"version_minor": 0
458+
}
454459
}
455460
},
456461
"nbformat": 4,

0 commit comments

Comments
 (0)