-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.py
More file actions
45 lines (39 loc) · 1.23 KB
/
default.py
File metadata and controls
45 lines (39 loc) · 1.23 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
"""
box-basic: Basic Box Plot
Library: altair
"""
import altair as alt
import numpy as np
import pandas as pd
# Data
np.random.seed(42)
data = pd.DataFrame(
{
"group": ["A"] * 50 + ["B"] * 50 + ["C"] * 50 + ["D"] * 50,
"value": np.concatenate(
[
np.random.normal(50, 10, 50),
np.random.normal(60, 15, 50),
np.random.normal(45, 8, 50),
np.random.normal(70, 20, 50),
]
),
}
)
# Color palette from style guide
colors = ["#306998", "#FFD43B", "#DC2626", "#059669"]
# Create chart
chart = (
alt.Chart(data)
.mark_boxplot(size=60, outliers={"size": 8})
.encode(
x=alt.X("group:N", title="Group", axis=alt.Axis(labelFontSize=16, titleFontSize=20)),
y=alt.Y("value:Q", title="Value", axis=alt.Axis(labelFontSize=16, titleFontSize=20)),
color=alt.Color("group:N", scale=alt.Scale(domain=["A", "B", "C", "D"], range=colors), legend=None),
)
.properties(width=1600, height=900, title=alt.Title("Basic Box Plot", fontSize=20))
.configure_view(strokeWidth=0)
.configure_axis(grid=True, gridOpacity=0.3)
)
# Save (4800 × 2700 px via scale_factor=3)
chart.save("plot.png", scale_factor=3.0)