-
Notifications
You must be signed in to change notification settings - Fork 348
/
Copy pathreactive_plots.py
89 lines (71 loc) · 1.74 KB
/
reactive_plots.py
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
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "altair==5.4.1",
# "marimo",
# "vega-datasets==0.9.0",
# ]
# ///
import marimo
__generated_with = "0.8.19"
app = marimo.App(width="full")
@app.cell(hide_code=True)
def __(mo):
mo.md("""# Welcome to marimo!""")
return
@app.cell
def __(bars, mo, scatter):
chart = mo.ui.altair_chart(scatter & bars)
chart
return (chart,)
@app.cell
def __(chart, mo):
(filtered_data := mo.ui.table(chart.value))
return (filtered_data,)
@app.cell
def __(alt, filtered_data, mo):
mo.stop(not len(filtered_data.value))
mpg_hist = mo.ui.altair_chart(
alt.Chart(filtered_data.value)
.mark_bar()
.encode(alt.X("Miles_per_Gallon:Q", bin=True), y="count()")
)
horsepower_hist = mo.ui.altair_chart(
alt.Chart(filtered_data.value)
.mark_bar()
.encode(alt.X("Horsepower:Q", bin=True), y="count()")
)
mo.hstack([mpg_hist, horsepower_hist], justify="space-around", widths="equal")
return horsepower_hist, mpg_hist
@app.cell
def __(alt, data):
cars = data.cars()
brush = alt.selection_interval()
scatter = (
alt.Chart(cars)
.mark_point()
.encode(
x="Horsepower",
y="Miles_per_Gallon",
color="Origin",
)
.add_params(brush)
)
bars = (
alt.Chart(cars)
.mark_bar()
.encode(y="Origin:N", color="Origin:N", x="count(Origin):Q")
.transform_filter(brush)
)
return bars, brush, cars, scatter
@app.cell
def __():
import altair as alt
from vega_datasets import data
return alt, data
@app.cell
def __():
import marimo as mo
return (mo,)
if __name__ == "__main__":
app.run()