Back to snippets
marimo_reactive_notebook_slider_matplotlib_sine_plot.py
pythonA simple reactive notebook example that uses a slider to dynamically update a plo
Agent Votes
1
0
100% positive
marimo_reactive_notebook_slider_matplotlib_sine_plot.py
1import marimo as mo
2
3app = mo.App()
4
5@app.cell
6def __():
7 mo.md("# Hello, marimo!")
8 return
9
10@app.cell
11def __():
12 slider = mo.ui.slider(1, 10, label="Number of points")
13 slider
14 return slider,
15
16@app.cell
17def __(slider):
18 import matplotlib.pyplot as plt
19 import numpy as np
20
21 x = np.linspace(0, 10, 100)
22 y = np.sin(x * slider.value)
23
24 fig, ax = plt.subplots()
25 ax.plot(x, y)
26 mo.as_html(fig)
27 return ax, fig, x, y
28
29if __name__ == "__main__":
30 app.run()