Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 52 additions & 29 deletions plots/line-multi/implementations/python/pygal.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
""" pyplots.ai
""" anyplot.ai
line-multi: Multi-Line Comparison Plot
Library: pygal 3.1.0 | Python 3.13.11
Quality: 91/100 | Created: 2025-12-24
Library: pygal 3.1.0 | Python 3.13.13
Quality: 83/100 | Updated: 2026-05-06
"""

import pygal
from pygal.style import Style
import os
import sys
from pathlib import Path


# Remove the script's directory from sys.path to avoid import collision
script_dir = str(Path(__file__).parent)
sys.path = [p for p in sys.path if p != script_dir and p != ""]

import pygal # noqa: E402
from pygal.style import Style # noqa: E402


# Theme tokens (see prompts/default-style-guide.md)
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
INK_MUTED = "#6B6A63" if THEME == "light" else "#A8A79F"

# Okabe-Ito palette (canonical order)
OKABE_ITO = (
"#009E73", # bluish green (brand — first series)
"#D55E00", # vermillion
"#0072B2", # blue
"#CC79A7", # reddish purple
)

# Data - Monthly sales for 4 product lines over 12 months
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

Expand All @@ -16,44 +41,41 @@
home_goods = [28, 31, 35, 38, 42, 45, 48, 52, 49, 55, 62, 72]
sports = [22, 25, 32, 45, 58, 65, 72, 68, 55, 42, 35, 28]

# Custom style for large canvas
# Custom style with theme-adaptive colors
custom_style = Style(
background="white",
plot_background="white",
foreground="#333333",
foreground_strong="#333333",
foreground_subtle="#666666",
colors=("#306998", "#FFD43B", "#E85D04", "#2A9D8F"), # Python colors + colorblind-safe
title_font_size=72,
label_font_size=48,
major_label_font_size=42,
legend_font_size=42,
value_font_size=36,
stroke_width=8,
opacity=0.9,
opacity_hover=1.0,
background=PAGE_BG,
plot_background=PAGE_BG,
foreground=INK,
foreground_strong=INK,
foreground_subtle=INK_MUTED,
colors=OKABE_ITO,
title_font_size=28,
label_font_size=22,
major_label_font_size=18,
legend_font_size=16,
value_font_size=14,
stroke_width=3,
)

# Create chart
chart = pygal.Line(
width=4800,
height=2700,
title="line-multi \u00b7 pygal \u00b7 pyplots.ai",
title="line-multi · pygal · anyplot.ai",
x_title="Month",
y_title="Sales (thousands USD)",
style=custom_style,
show_dots=True,
dots_size=12,
dots_size=6,
show_legend=True,
legend_at_bottom=False,
legend_box_size=36,
x_label_rotation=0,
show_y_guides=True,
show_x_guides=False,
margin=80,
margin_top=150,
margin_bottom=150,
spacing=40,
margin=100,
margin_top=120,
margin_bottom=100,
spacing=20,
)

# Add data series
Expand All @@ -64,5 +86,6 @@
chart.add("Sports", sports)

# Save as PNG and HTML
chart.render_to_png("plot.png")
chart.render_to_file("plot.html")
chart.render_to_png(f"plot-{THEME}.png")
with open(f"plot-{THEME}.html", "wb") as f:
f.write(chart.render())
Loading
Loading