Skip to content

Commit a5b9bfe

Browse files
github-actions[bot]claudeMarkusNeusinger
authored
feat(pygal): implement line-timeseries (#6121)
## Implementation: `line-timeseries` - python/pygal Implements the **python/pygal** version of `line-timeseries`. **File:** `plots/line-timeseries/implementations/python/pygal.py` **Parent Issue:** #2006 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25590470019)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent 9f3b78b commit a5b9bfe

2 files changed

Lines changed: 193 additions & 161 deletions

File tree

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
line-timeseries: Time Series Line Plot
3-
Library: pygal 3.1.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-26
3+
Library: pygal 3.1.0 | Python 3.13.13
4+
Quality: 85/100 | Updated: 2026-05-09
55
"""
66

7+
import os
78
import random
9+
import sys
810
from datetime import datetime, timedelta
911

10-
import pygal
11-
from pygal.style import Style
1212

13+
# Ensure site-packages is in path before current directory to avoid shadowing
14+
site_packages = next((p for p in sys.path if "site-packages" in p), None)
15+
if site_packages and sys.path[0] == os.path.dirname(__file__):
16+
sys.path.remove(sys.path[0])
17+
sys.path.insert(0, site_packages)
18+
19+
import pygal # noqa: E402
20+
from pygal.style import Style # noqa: E402
21+
22+
23+
# Theme tokens
24+
THEME = os.getenv("ANYPLOT_THEME", "light")
25+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
26+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
27+
INK_MUTED = "#6B6A63" if THEME == "light" else "#A8A79F"
28+
29+
# Okabe-Ito palette
30+
OKABE_ITO = ("#009E73", "#D55E00", "#0072B2", "#CC79A7", "#E69F00", "#56B4E9", "#F0E442")
1331

1432
# Seed for reproducibility
1533
random.seed(42)
@@ -22,45 +40,42 @@
2240
price = 150.0
2341
prices = []
2442
for _ in range(365):
25-
# Add slight upward trend with random daily changes
2643
change = random.gauss(0.1, 2.5)
27-
price = max(100, price + change) # Prevent going too low
44+
price = max(100, price + change)
2845
prices.append(round(price, 2))
2946

30-
# Custom style for 4800x2700 canvas with larger fonts
47+
# Custom style for 4800x2700 canvas
3148
custom_style = Style(
32-
background="white",
33-
plot_background="white",
34-
foreground="#333333",
35-
foreground_strong="#333333",
36-
foreground_subtle="#666666",
37-
colors=("#306998",), # Python Blue
38-
title_font_size=72,
39-
label_font_size=48,
40-
major_label_font_size=42,
41-
legend_font_size=42,
42-
value_font_size=36,
43-
guide_stroke_color="#cccccc",
44-
guide_stroke_dasharray="2,4",
49+
background=PAGE_BG,
50+
plot_background=PAGE_BG,
51+
foreground=INK,
52+
foreground_strong=INK,
53+
foreground_subtle=INK_MUTED,
54+
colors=OKABE_ITO,
55+
title_font_size=28,
56+
label_font_size=22,
57+
major_label_font_size=18,
58+
legend_font_size=16,
59+
value_font_size=14,
60+
stroke_width=6,
4561
)
4662

4763
# Create line chart
4864
chart = pygal.Line(
4965
width=4800,
5066
height=2700,
5167
style=custom_style,
52-
title="line-timeseries · pygal · pyplots.ai",
68+
title="line-timeseries · pygal · anyplot.ai",
5369
x_title="Date",
5470
y_title="Stock Price (USD)",
55-
show_x_guides=False,
71+
show_x_guides=True,
5672
show_y_guides=True,
5773
x_label_rotation=45,
5874
show_legend=True,
5975
legend_at_bottom=True,
6076
truncate_legend=-1,
6177
show_dots=False,
62-
stroke_style={"width": 5},
63-
margin=60,
78+
margin=100,
6479
)
6580

6681
# Add data series
@@ -70,7 +85,7 @@
7085
x_labels = []
7186
x_labels_major = []
7287
for d in dates:
73-
if d.day == 1: # First of each month
88+
if d.day == 1:
7489
x_labels.append(d.strftime("%b %Y"))
7590
x_labels_major.append(d.strftime("%b %Y"))
7691
else:
@@ -80,5 +95,5 @@
8095
chart.x_labels_major = x_labels_major
8196

8297
# Save as PNG and HTML
83-
chart.render_to_file("plot.html")
84-
chart.render_to_png("plot.png")
98+
chart.render_to_file(f"plot-{THEME}.html")
99+
chart.render_to_png(f"plot-{THEME}.png")

0 commit comments

Comments
 (0)