3
3
import marimo
4
4
5
5
__generated_with = "0.12.0"
6
- app = marimo .App (
7
- width = "medium" ,
8
- app_title = "Intro to Marimo notebooks" ,
9
- layout_file = "layouts/mo_intro.slides.json" ,
10
- )
6
+ app = marimo .App (width = "medium" , app_title = "Intro to Marimo notebooks" )
11
7
12
8
13
9
@app .cell (hide_code = True )
14
10
def _ (mo ):
15
- mo .md (r"""# Marimo notebooks""" )
11
+ mo .md (r"""# Introduction to marimo notebooks""" )
16
12
return
17
13
18
14
@@ -89,6 +85,8 @@ def _(mo):
89
85
### Side effect
90
86
91
87
Variables cannot be redefined.
88
+
89
+ Try renaming the following variable from `_a` to `a` and run the cell.
92
90
"""
93
91
)
94
92
return
@@ -114,7 +112,7 @@ def _(mo, show_intro_nb):
114
112
115
113
@app .cell (hide_code = True )
116
114
def _ (mo ):
117
- mo .md (r"""All cells are just function with app.cell()app.cell() decorator.""" )
115
+ mo .md (r"""All cells are just function with ` app.cell()` decorator.""" )
118
116
return
119
117
120
118
@@ -209,7 +207,7 @@ def test_function(function_to_test):
209
207
def _ (mo ):
210
208
mo .md (
211
209
r"""
212
- Name cells that contain a test_... "test_..." and run pytest on your notebook.
210
+ Name cells that contain a "test_..." and run pytest on your notebook.
213
211
214
212
```bash
215
213
$ pytest notebooks/mo_intro.py
@@ -261,16 +259,17 @@ def _(mo):
261
259
262
260
263
261
@app .cell
264
- def _ (mo ):
265
- import pandas as pd
262
+ def _ ():
263
+ from nilearn . glm . tests . _testing import modulated_event_paradigm
266
264
267
- nilearn_repos = pd .read_csv (mo .notebook_location () / "public" / "nilearn_repos.csv" )
268
- return nilearn_repos , pd
265
+ events = modulated_event_paradigm ()
266
+ events
267
+ return events , modulated_event_paradigm
269
268
270
269
271
270
@app .cell
272
- def _ (mo , nilearn_repos ):
273
- transformed_df = mo .ui .dataframe (nilearn_repos )
271
+ def _ (events , mo ):
272
+ transformed_df = mo .ui .dataframe (events )
274
273
transformed_df
275
274
return (transformed_df ,)
276
275
@@ -283,88 +282,27 @@ def _(mo):
283
282
284
283
@app .cell
285
284
def _ (mo ):
286
- options = ["" , "extracted_version" ]
287
- radio = mo .ui .radio (options = options )
288
- return options , radio
285
+ slider = mo .ui .slider (start = 0 , stop = 7 , step = 1 , label = "Thresold" , value = 2 )
286
+ return (slider ,)
289
287
290
288
291
- @app .cell (hide_code = True )
292
- def _ (mo , nilearn_repos , plot_repos , radio ):
293
- repo_fig = plot_repos (nilearn_repos , color = radio .value )
294
- repo_fig .show ()
295
-
296
- mo .hstack (
297
- [
298
- mo .vstack ([mo .md ("color" ), radio ]),
299
- ],
300
- align = "center" ,
301
- )
302
- return (repo_fig ,)
289
+ @app .cell
290
+ def _ (slider ):
291
+ slider
292
+ return
303
293
304
294
305
295
@app .cell
306
- def _ ():
296
+ def _ (slider ):
307
297
from nilearn .datasets import load_sample_motor_activation_image
308
298
from nilearn .plotting import view_img
309
299
310
300
stat_map = load_sample_motor_activation_image ()
311
301
312
- view_img (stat_map , threshold = 3 )
302
+ view_img (stat_map , threshold = slider . value )
313
303
return load_sample_motor_activation_image , stat_map , view_img
314
304
315
305
316
- @app .cell
317
- def _ (mo ):
318
- def foo (a ):
319
- a
320
-
321
- mo .md (
322
- r"""
323
- ## Qualite of life improvements
324
-
325
- - tab completion
326
- - type 'aware'
327
- """
328
- )
329
- return (foo ,)
330
-
331
-
332
- @app .cell (hide_code = True )
333
- def _ (mo ):
334
- mo .md (
335
- r"""
336
- ## Personal remarks
337
-
338
- ### ➕
339
-
340
- - impossibility to dynamically reuse variables,
341
- nudge users to create functions to encapsulate things
342
- - automatic execution of cells that are resource intensive
343
- is annoying, so it nudges users to have save data at bottlenecks.
344
-
345
- ### ➖
346
-
347
- - sometimes when stopping a notebook execution,
348
- you have to reexcute some cells manually
349
- for the notebook execution to continue.
350
- """
351
- )
352
- return
353
-
354
-
355
- @app .cell (hide_code = True )
356
- def _ (mo ):
357
- mo .md (
358
- r"""
359
- ## Not mentioned
360
-
361
- - code snippets
362
- - deploy to github pages and other places
363
- """
364
- )
365
- return
366
-
367
-
368
306
@app .cell
369
307
def _ ():
370
308
import marimo as mo
@@ -406,57 +344,5 @@ def show_intro_nb(break_condition: str = "def cell_2(") -> str:
406
344
return (show_intro_nb ,)
407
345
408
346
409
- @app .cell (hide_code = True )
410
- def _ (pd ):
411
- import matplotlib .colors as mcolors
412
- import matplotlib .pyplot as plt
413
- import plotly .express as px
414
- from packaging .version import Version
415
-
416
- def plot_repos (df : pd .DataFrame , color : str | None = None ):
417
- if color == "" :
418
- color = None
419
-
420
- df .drop_duplicates (subset = ["name" ])
421
- df = df [df ["include" ]]
422
-
423
- category_orders = None
424
- color_map = None
425
- if color :
426
- df = df .dropna (subset = [color ])
427
-
428
- # Sort version labels naturally
429
- category_orders = {color : sorted (df [color ].unique ())}
430
- if color == "extracted_version" :
431
- ordered_versions = sorted (df [color ].unique (), key = Version )
432
- category_orders = {color : ordered_versions }
433
-
434
- # Get Jet colors for each version using matplotlib
435
- cmap = plt .get_cmap ("jet" , len (ordered_versions ))
436
- color_map = [mcolors .to_hex (cmap (i )) for i in range (len (ordered_versions ))]
437
-
438
- start_date = df ["last_commit" ].min ()
439
- end_date = df ["last_commit" ].max ()
440
-
441
- fig = px .histogram (
442
- df ,
443
- x = "last_commit" ,
444
- color = color ,
445
- category_orders = category_orders ,
446
- color_discrete_sequence = color_map ,
447
- title = f"Analysis of { len (df )} repositories" ,
448
- )
449
-
450
- fig .update_layout (xaxis_title = "Last Commit Date" , yaxis_title = "Usage Count" )
451
-
452
- fig .update_xaxes (tickformat = "%Y-%m" )
453
-
454
- # Update the x-axis bin size to 3 months
455
- fig .update_traces (xbins = {"start" : start_date , "end" : end_date , "size" : "M3" })
456
-
457
- return fig
458
- return Version , mcolors , plot_repos , plt , px
459
-
460
-
461
347
if __name__ == "__main__" :
462
348
app .run ()
0 commit comments