{"spec_id":"line-timeseries","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nline-timeseries: Time Series Line Plot\nLibrary: pygal 3.1.3 | Python 3.14.8\nQuality: 80/100 | Updated: 2026-10-28\n\"\"\"\n\nimport os\nimport random\nfrom datetime import datetime, timedelta\n\nimport pandas as pd\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# Imprint palette: all eight positions in canonical order\nIMPRINT_PALETTE = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\")\n\n# Columns: set these to your table's column names\nDATE = \"Date\"  # role: date\nPRICE = \"Stock Price (USD)\"  # role: value\n\n# Data: replace this block with your own table, for example df = pd.read_csv(\"prices.csv\", parse_dates=[DATE])\nrandom.seed(42)\nprice = 150.0\nprices = []\nfor _ in range(365):\n    price = max(100, price + random.gauss(0.1, 2.5))\n    prices.append(round(price, 2))\ndf = pd.DataFrame({DATE: [datetime(2024, 1, 1) + timedelta(days=i) for i in range(365)], PRICE: prices})\n\n# Plot\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_PALETTE,\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=5,\n)\n\nchart = pygal.Line(\n    width=3200,\n    height=1800,\n    style=custom_style,\n    title=\"line-timeseries · pygal · anyplot.ai\",\n    x_title=DATE,\n    y_title=PRICE,\n    show_x_guides=True,\n    show_y_guides=True,\n    x_label_rotation=45,\n    show_legend=False,\n    show_dots=False,\n)\n\nchart.add(PRICE, df[PRICE].tolist())\n\n# Label only the first day of each month; the other days stay blank\nis_month_start = df[DATE].dt.day == 1\nmonth_labels = df[DATE].dt.strftime(\"%b %Y\").where(is_month_start, \"\").tolist()\nchart.x_labels = month_labels\nchart.x_labels_major = [label for label in month_labels if label]\n\n# Save\nchart.render_to_file(f\"plot-{THEME}.html\")\nchart.render_to_png(f\"plot-{THEME}.png\")\n"}