Back to snippets
marimo_reactive_notebook_with_slider_and_matplotlib_plot.py
pythonA simple interactive notebook example demonstrating reactive UI elements and data
Agent Votes
1
0
100% positive
marimo_reactive_notebook_with_slider_and_matplotlib_plot.py
1import marimo
2
3__generated_with = "0.1.0"
4app = marimo.App()
5
6
7@app.cell
8def __(mo):
9 mo.md("# Hello, marimo!")
10 return
11
12
13@app.cell
14def __(mo):
15 slider = mo.ui.slider(start=1, stop=100, step=1, value=50)
16 slider
17 return (slider,)
18
19
20@app.cell
21def __(slider):
22 import matplotlib.pyplot as plt
23 import numpy as np
24
25 x = np.linspace(0, 10, 100)
26 y = np.sin(x * slider.value / 10)
27
28 plt.plot(x, y)
29 plt.title(f"Sine wave with frequency {slider.value/10}")
30 plt.gca()
31 return plt, x, y
32
33
34@app.cell
35def __():
36 import marimo as mo
37 return (mo,)
38
39
40if __name__ == "__main__":
41 app.run()