diff --git a/book/features/widgets.ipynb b/book/features/widgets.ipynb index f63bbcc..361cb93 100644 --- a/book/features/widgets.ipynb +++ b/book/features/widgets.ipynb @@ -10,18 +10,22 @@ "\n", "## `matplotlib` widgets\n", "When you'd like to use `ipywidgets` in combinations with a `matplotlib` figure, import the following packages:\n", - "```{python}\n", + "\n", + "```python\n", "import ipywidgets as widgets\n", "import micropip\n", "await micropip.install(\"ipympl\")\n", "```\n", + "\n", "Activate the correct output format:\n", - "```{python}\n", + "\n", + "```python\n", "%matplotlib widget\n", "```\n", "\n", "Write the code which generates your plot in a function:\n", - "```{python}\n", + "\n", + "```python\n", "fig = plt.figure() # Define the figure once\n", "ax = fig.add_subplot(1,1,1) # Define the axis once\n", "\n", @@ -30,8 +34,10 @@ " ax.plot(x,y) # Plot your actual data\n", " plt.draw() # Update the plot whenever this function is executed\n", "```\n", + "\n", "Initiate the widget:\n", - "```{python}\n", + "\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"