{"spec_id":"line-multi","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nline-multi: Multi-Line Comparison Plot\nLibrary: pygal 3.1.3 | Python 3.13.14\nQuality: 94/100 | Updated: 2026-08-05\n\"\"\"\n\nimport os\nimport sys\nfrom pathlib import Path\n\n\n# Remove the script's directory from sys.path to avoid import collision\nscript_dir = str(Path(__file__).parent)\nsys.path = [p for p in sys.path if p != script_dir and p != \"\"]\n\nimport pygal\nfrom pygal.style import Style\n\n\n# Theme tokens (see prompts/default-style-guide.md)\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\n# Imprint palette (canonical order)\nIMPRINT = (\n    \"#009E73\",  # brand green (brand — first series)\n    \"#C475FD\",  # lavender\n    \"#4467A3\",  # blue\n    \"#BD8233\",  # ochre\n)\n\n# Data - Monthly sales for 4 product lines over 12 months\nmonths = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\n\nelectronics = [45, 52, 48, 61, 55, 67, 72, 78, 69, 85, 92, 110]\nclothing = [38, 42, 51, 48, 55, 62, 58, 65, 71, 68, 75, 88]\nhome_goods = [28, 31, 35, 38, 42, 45, 48, 52, 49, 55, 62, 72]\nsports = [22, 25, 32, 45, 58, 65, 72, 68, 55, 42, 35, 28]\n\n# Custom style with theme-adaptive colors\n# Sizing per prompts/library/pygal.md \"Sizing + Theme for 3200x1800 px\"\ncustom_style = Style(\n    background=PAGE_BG,\n    plot_background=PAGE_BG,\n    foreground=INK,\n    foreground_strong=INK,\n    foreground_subtle=INK_MUTED,\n    colors=IMPRINT,\n    font_family='\"Helvetica Neue\", Helvetica, Arial, \"DejaVu Sans\", sans-serif',\n    title_font_size=66,\n    label_font_size=56,\n    major_label_font_size=44,\n    legend_font_size=44,\n    value_font_size=36,\n    stroke_width=2.5,\n    legend_box_size=30,\n)\n\n# Create chart\nchart = pygal.Line(\n    width=3200,\n    height=1800,\n    title=\"line-multi · python · pygal · anyplot.ai\",\n    x_title=\"Month\",\n    y_title=\"Sales (thousands USD)\",\n    style=custom_style,\n    # Hermite/cardinal interpolation passes through every monthly value\n    # exactly (unlike smoothing) while replacing the plain polyline with a\n    # gently curved one — a distinctive pygal-only touch that lifts the\n    # aesthetic beyond straight-segment defaults.\n    interpolate=\"hermite\",\n    interpolation_parameters={\"type\": \"cardinal\", \"c\": 0.25},\n    interpolation_precision=250,\n    show_dots=True,\n    dots_size=7,\n    show_legend=True,\n    legend_at_bottom=False,\n    x_label_rotation=0,\n    show_y_guides=True,\n    show_x_guides=False,\n    margin_top=140,\n    margin_bottom=90,\n    margin_left=100,\n    margin_right=40,\n    spacing=24,\n)\n\n# Add data series — Electronics gets a bolder solid stroke and larger dots to\n# lead the eye toward its steady growth story; the remaining series use\n# distinct dash patterns for redundant encoding alongside color.\nchart.x_labels = months\nchart.add(\"Electronics\", electronics, stroke_style={\"width\": 4}, dots_size=9)\nchart.add(\"Clothing\", clothing, stroke_style={\"width\": 2.5, \"dasharray\": \"10, 6\"})\nchart.add(\"Home Goods\", home_goods, stroke_style={\"width\": 2.5, \"dasharray\": \"2, 6\"})\nchart.add(\"Sports\", sports, stroke_style={\"width\": 2.5, \"dasharray\": \"14, 6, 2, 6\"})\n\n# Save as PNG and HTML\nchart.render_to_png(f\"plot-{THEME}.png\")\nwith open(f\"plot-{THEME}.html\", \"wb\") as f:\n    f.write(chart.render())\n"}