{"spec_id":"line-timeseries","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nline-timeseries: Time Series Line Plot\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 85/100 | Updated: 2026-05-09\n\"\"\"\n\nimport os\nimport random\nimport sys\nfrom datetime import datetime, timedelta\n\n\n# Ensure site-packages is in path before current directory to avoid shadowing\nsite_packages = next((p for p in sys.path if \"site-packages\" in p), None)\nif site_packages and sys.path[0] == os.path.dirname(__file__):\n    sys.path.remove(sys.path[0])\n    sys.path.insert(0, site_packages)\n\nimport pygal\nfrom pygal.style import Style\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\n# Okabe-Ito palette\nIMPRINT = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\")\n\n# Seed for reproducibility\nrandom.seed(42)\n\n# Generate realistic daily stock price data for one year\nstart_date = datetime(2024, 1, 1)\ndates = [start_date + timedelta(days=i) for i in range(365)]\n\n# Simulate stock price with trend and volatility\nprice = 150.0\nprices = []\nfor _ in range(365):\n    change = random.gauss(0.1, 2.5)\n    price = max(100, price + change)\n    prices.append(round(price, 2))\n\n# Custom style for 4800x2700 canvas\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    title_font_size=28,\n    label_font_size=22,\n    major_label_font_size=18,\n    legend_font_size=16,\n    value_font_size=14,\n    stroke_width=6,\n)\n\n# Create line chart\nchart = pygal.Line(\n    width=4800,\n    height=2700,\n    style=custom_style,\n    title=\"line-timeseries · pygal · anyplot.ai\",\n    x_title=\"Date\",\n    y_title=\"Stock Price (USD)\",\n    show_x_guides=True,\n    show_y_guides=True,\n    x_label_rotation=45,\n    show_legend=True,\n    legend_at_bottom=True,\n    truncate_legend=-1,\n    show_dots=False,\n    margin=100,\n)\n\n# Add data series\nchart.add(\"ACME Corp Stock\", prices)\n\n# Set x-axis labels - show first of each month only\nx_labels = []\nx_labels_major = []\nfor d in dates:\n    if d.day == 1:\n        x_labels.append(d.strftime(\"%b %Y\"))\n        x_labels_major.append(d.strftime(\"%b %Y\"))\n    else:\n        x_labels.append(\"\")\n\nchart.x_labels = x_labels\nchart.x_labels_major = x_labels_major\n\n# Save as PNG and HTML\nchart.render_to_file(f\"plot-{THEME}.html\")\nchart.render_to_png(f\"plot-{THEME}.png\")\n"}