Skip to content

Commit 69b1f1c

Browse files
feat(altair): implement line-timeseries (#6119)
## Implementation: `line-timeseries` - python/altair Implements the **python/altair** version of `line-timeseries`. **File:** `plots/line-timeseries/implementations/python/altair.py` **Parent Issue:** #2006 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25590385550)* --------- 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 4122f65 commit 69b1f1c

2 files changed

Lines changed: 202 additions & 142 deletions

File tree

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
line-timeseries: Time Series Line Plot
3-
Library: altair 6.0.0 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-26
3+
Library: altair 6.1.0 | Python 3.13.13
4+
Quality: 92/100 | Updated: 2026-05-09
55
"""
66

7-
import altair as alt
8-
import numpy as np
9-
import pandas as pd
7+
import os
8+
import sys
109

1110

11+
# Remove the current directory from sys.path to avoid importing altair.py
12+
sys.path = [p for p in sys.path if p != "" and not p.endswith("python")]
13+
14+
import altair as alt # noqa: E402
15+
import numpy as np # noqa: E402
16+
import pandas as pd # noqa: E402
17+
18+
19+
# Theme tokens
20+
THEME = os.getenv("ANYPLOT_THEME", "light")
21+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
22+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
23+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
24+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
25+
BRAND = "#009E73" # Okabe-Ito position 1
26+
1227
# Data - Daily stock prices over one year
1328
np.random.seed(42)
1429

@@ -29,41 +44,56 @@
2944
# Create time series line chart
3045
chart = (
3146
alt.Chart(df)
32-
.mark_line(
33-
strokeWidth=3,
34-
color="#306998", # Python Blue
35-
)
47+
.mark_line(strokeWidth=3, color=BRAND, point=True, size=150)
3648
.encode(
3749
x=alt.X(
3850
"date:T",
3951
title="Date",
4052
axis=alt.Axis(
41-
format="%b %Y", # Month Year format
53+
format="%b %Y",
4254
labelFontSize=18,
4355
titleFontSize=22,
4456
labelAngle=-45,
4557
tickCount=12,
58+
labelColor=INK_SOFT,
59+
titleColor=INK,
60+
domainColor=INK_SOFT,
61+
gridColor=INK,
62+
gridOpacity=0.10,
4663
),
4764
),
4865
y=alt.Y(
4966
"price:Q",
5067
title="Stock Price ($)",
5168
scale=alt.Scale(zero=False),
52-
axis=alt.Axis(labelFontSize=18, titleFontSize=22, grid=True, gridOpacity=0.3),
69+
axis=alt.Axis(
70+
labelFontSize=18,
71+
titleFontSize=22,
72+
labelColor=INK_SOFT,
73+
titleColor=INK,
74+
domainColor=INK_SOFT,
75+
gridColor=INK,
76+
gridOpacity=0.10,
77+
),
5378
),
5479
tooltip=[
5580
alt.Tooltip("date:T", title="Date", format="%B %d, %Y"),
5681
alt.Tooltip("price:Q", title="Price", format="$.2f"),
5782
],
5883
)
5984
.properties(
60-
width=1600, height=900, title=alt.Title("line-timeseries · altair · pyplots.ai", fontSize=28, anchor="middle")
85+
width=1600,
86+
height=900,
87+
background=PAGE_BG,
88+
title=alt.Title("line-timeseries · altair · anyplot.ai", fontSize=28, anchor="middle", color=INK),
6189
)
62-
.configure_view(strokeWidth=0)
63-
.configure_axis(gridColor="#cccccc", gridOpacity=0.3, domainColor="#333333")
90+
.configure_view(fill=PAGE_BG, stroke=INK_SOFT, strokeWidth=1)
91+
.configure_title(color=INK, fontSize=28)
92+
.configure_legend(fillColor=ELEVATED_BG, strokeColor=INK_SOFT, labelColor=INK_SOFT, titleColor=INK)
6493
.interactive()
6594
)
6695

6796
# Save outputs
68-
chart.save("plot.png", scale_factor=3.0)
69-
chart.save("plot.html")
97+
script_dir = os.path.dirname(os.path.abspath(__file__))
98+
chart.save(os.path.join(script_dir, f"plot-{THEME}.png"), scale_factor=3.0)
99+
chart.save(os.path.join(script_dir, f"plot-{THEME}.html"))

0 commit comments

Comments
 (0)