Skip to content

Commit 49f5a4b

Browse files
feat(altair): implement line-basic (#5540)
## Implementation: `line-basic` - python/altair Implements the **python/altair** version of `line-basic`. **File:** `plots/line-basic/implementations/python/altair.py` **Parent Issue:** #653 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25117106624)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent b523eb5 commit 49f5a4b

2 files changed

Lines changed: 204 additions & 143 deletions

File tree

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,70 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
line-basic: Basic Line Plot
3-
Library: altair 6.0.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: altair 6.1.0 | Python 3.13.13
4+
Quality: 86/100 | Updated: 2026-04-29
55
"""
66

7+
import os
8+
79
import altair as alt
810
import numpy as np
911
import pandas as pd
1012

1113

14+
# Theme tokens
15+
THEME = os.getenv("ANYPLOT_THEME", "light")
16+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
17+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
18+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
19+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
20+
BRAND = "#009E73"
21+
1222
# Data - Monthly temperature readings over a year
1323
np.random.seed(42)
1424
months = pd.date_range(start="2024-01-01", periods=12, freq="MS")
15-
# Simulate temperature pattern (cold in winter, warm in summer)
1625
base_temp = 15 + 12 * np.sin((np.arange(12) - 3) * np.pi / 6)
1726
temperature = base_temp + np.random.randn(12) * 2
18-
1927
df = pd.DataFrame({"Month": months, "Temperature": temperature})
2028

2129
# Plot
22-
chart = (
30+
tooltip_enc = [
31+
alt.Tooltip("Month:T", title="Month", format="%B %Y"),
32+
alt.Tooltip("Temperature:Q", title="Temperature (°C)", format=".1f"),
33+
]
34+
35+
line = (
2336
alt.Chart(df)
24-
.mark_line(strokeWidth=4, color="#306998")
25-
.encode(
26-
x=alt.X("Month:T", title="Month", axis=alt.Axis(labelFontSize=18, titleFontSize=22)),
27-
y=alt.Y("Temperature:Q", title="Temperature (°C)", axis=alt.Axis(labelFontSize=18, titleFontSize=22)),
28-
)
29-
.properties(width=1600, height=900, title=alt.Title("line-basic · altair · pyplots.ai", fontSize=28))
37+
.mark_line(strokeWidth=4, color=BRAND)
38+
.encode(x=alt.X("Month:T", title="Month"), y=alt.Y("Temperature:Q", title="Temperature (°C)"))
3039
)
3140

32-
# Add points to enhance visibility
33-
points = alt.Chart(df).mark_point(size=200, color="#306998", filled=True).encode(x="Month:T", y="Temperature:Q")
41+
points = (
42+
alt.Chart(df)
43+
.mark_point(size=200, color=BRAND, filled=True)
44+
.encode(x="Month:T", y="Temperature:Q", tooltip=tooltip_enc)
45+
)
3446

35-
# Combine line and points with subtle grid
36-
final_chart = (chart + points).configure_axis(gridColor="#E0E0E0", gridOpacity=0.3).configure_view(strokeWidth=0)
47+
chart = (
48+
(line + points)
49+
.interactive()
50+
.properties(
51+
width=1600, height=900, title=alt.Title("line-basic · altair · anyplot.ai", fontSize=28), background=PAGE_BG
52+
)
53+
.configure_view(fill=PAGE_BG, stroke=INK_SOFT)
54+
.configure_axis(
55+
domainColor=INK_SOFT,
56+
tickColor=INK_SOFT,
57+
gridColor=INK,
58+
gridOpacity=0.15,
59+
labelColor=INK_SOFT,
60+
titleColor=INK,
61+
labelFontSize=18,
62+
titleFontSize=22,
63+
)
64+
.configure_title(color=INK, fontSize=28)
65+
.configure_legend(fillColor=ELEVATED_BG, strokeColor=INK_SOFT, labelColor=INK_SOFT, titleColor=INK)
66+
)
3767

3868
# Save
39-
final_chart.save("plot.png", scale_factor=3.0)
40-
final_chart.save("plot.html")
69+
chart.save(f"plot-{THEME}.png", scale_factor=3.0)
70+
chart.save(f"plot-{THEME}.html")

0 commit comments

Comments
 (0)