mirror of
https://github.com/TeachBooks/manual.git
synced 2026-11-13 14:55:51 +00:00
Update widgets.ipynb
This commit is contained in:
parent
71149813fc
commit
fb9d54915c
1 changed files with 4 additions and 4 deletions
|
|
@ -11,7 +11,7 @@
|
|||
"## `matplotlib` widgets\n",
|
||||
"When you'd like to use `ipywidgets` in combinations with a `matplotlib` figure, import the following packages:\n",
|
||||
"\n",
|
||||
"```{python}\n",
|
||||
"```python\n",
|
||||
"import ipywidgets as widgets\n",
|
||||
"import micropip\n",
|
||||
"await micropip.install(\"ipympl\")\n",
|
||||
|
|
@ -19,13 +19,13 @@
|
|||
"\n",
|
||||
"Activate the correct output format:\n",
|
||||
"\n",
|
||||
"```{python}\n",
|
||||
"```python\n",
|
||||
"%matplotlib widget\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Write the code which generates your plot in a function:\n",
|
||||
"\n",
|
||||
"```{python}\n",
|
||||
"```python\n",
|
||||
"fig = plt.figure() # Define the figure once\n",
|
||||
"ax = fig.add_subplot(1,1,1) # Define the axis once\n",
|
||||
"\n",
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
"\n",
|
||||
"Initiate the widget:\n",
|
||||
"\n",
|
||||
"```{python}\n",
|
||||
"```python\n",
|
||||
"input_slider = widgets.FloatSlider(value=0, min=0, max=10, step=1, description='Input variable:') # Defines a widget, more options than just FloatSlider\n",
|
||||
"widgets.interact(update_plot, input_variable_from_widget = input_slider);\n",
|
||||
"```\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue