-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInteractive.py
More file actions
124 lines (85 loc) · 2 KB
/
Interactive.py
File metadata and controls
124 lines (85 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import marimo
__generated_with = "0.13.4"
app = marimo.App(width="medium")
@app.cell
def _(mo):
mo.md(
r"""
# Paper Title
_Authors:_ Author One (Affiliation), Author Two (Affiliation)
This notebook is part of the publication "Paper Title" (Publication information, [doi:XXX](https://doi.org/)).
"""
)
return
@app.cell
def _(mo):
mo.md(
r"""
## Heading...
Add some text and explanations. You can use $\LaTeX$ commands, such as $\alpha$ or equations $$\int_{0}^{1} f(x) \mathrm{d} x = \pi$$
Also Marimo allows having interactive elements, such as sliders to manipulate parameters.
"""
)
return
@app.cell
def _(slider_noise_level):
slider_noise_level
return
@app.cell
def _(noise_level, np, plt, x):
_fig, _axs = plt.subplots()
y = np.sin(x) + noise_level * np.random.randn(len(x))
_axs.plot(x, y)
return
@app.cell
def _(mo):
mo.md(
r"""
## Code
In the following, we have necessary imports and code.
As Marimo builds a dependency tree of the cells, they can be in any order.
Therefore, we can keep the messy parts at the end of the notebook.
"""
)
return
@app.cell
def _(mo):
mo.md(
r"""
### Parameter Definitions
In this section, we define (global) parameters and interactive sliders.
"""
)
return
@app.cell
def _(np):
num_samples = 100
x = np.linspace(0, 10, num_samples)
return (x,)
@app.cell
def _(mo):
slider_noise_level = mo.ui.slider(0, 1, 0.1)
return (slider_noise_level,)
@app.cell
def _(slider_noise_level):
noise_level = slider_noise_level.value
return (noise_level,)
@app.cell
def _(mo):
mo.md(r"""### Function Definitions""")
return
@app.cell
def _():
return
@app.cell
def _(mo):
mo.md(r"""### Imports""")
return
@app.cell
def _():
import marimo as mo
import numpy as np
import matplotlib.pyplot as plt
return mo, np, plt
if __name__ == "__main__":
app.run()