{"spec_id":"sparkline-basic","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nsparkline-basic: Basic Sparkline\nLibrary: plotnine 0.15.7 | Python 3.13.13\nQuality: 89/100 | Updated: 2026-06-16\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    element_blank,\n    element_rect,\n    element_text,\n    geom_line,\n    geom_point,\n    geom_ribbon,\n    ggplot,\n    labs,\n    scale_color_manual,\n    theme,\n)\n\n\n# Theme tokens (see prompts/default-style-guide.md \"Theme-adaptive Chrome\")\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_MUTED = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Imprint palette — brand green is the single data series; the two extremes\n# read as a red/blue divergence (low extreme → matte red, high extreme → blue).\nBRAND = \"#009E73\"  # Imprint position 1 — always the first series\nLOW = \"#AE3030\"  # Imprint position 5 — semantic anchor for the minimum\nHIGH = \"#4467A3\"  # Imprint position 3 — the maximum (high extreme)\n\n# Data — simulated daily sales trend with seasonality and noise\nnp.random.seed(42)\nn_points = 50\n\ntrend = np.linspace(0, 3, n_points)\nseasonal = 2 * np.sin(np.linspace(0, 4 * np.pi, n_points))\nnoise = np.random.randn(n_points) * 0.8\nsales = 100 + trend * 10 + seasonal * 5 + noise * 3\n\ndf = pd.DataFrame({\"day\": range(n_points), \"sales\": sales})\n\n# Baseline for the subtle area fill — sits just below the lowest value so the\n# tinted band hugs the line rather than swelling from a zero baseline.\nfill_base = df[\"sales\"].min() - (df[\"sales\"].max() - df[\"sales\"].min()) * 0.15\n\n# Highlight the min, max, and the two endpoints for reference\nmin_idx = int(df[\"sales\"].idxmin())\nmax_idx = int(df[\"sales\"].idxmax())\n\nhighlight_df = pd.DataFrame(\n    {\n        \"day\": [min_idx, max_idx, 0, n_points - 1],\n        \"sales\": [\n            df.loc[min_idx, \"sales\"],\n            df.loc[max_idx, \"sales\"],\n            df.loc[0, \"sales\"],\n            df.loc[n_points - 1, \"sales\"],\n        ],\n        \"type\": [\"min\", \"max\", \"endpoint\", \"endpoint\"],\n    }\n)\n\n# Plot — minimal sparkline: subtle area fill, thin brand line, highlighted\n# extremes/endpoints. The ribbon adds quiet storytelling without chrome.\nplot = (\n    ggplot(df, aes(x=\"day\", y=\"sales\"))\n    + geom_ribbon(aes(ymin=fill_base, ymax=\"sales\"), fill=BRAND, alpha=0.12)\n    + geom_line(color=BRAND, size=1.3)\n    + geom_point(data=highlight_df, mapping=aes(x=\"day\", y=\"sales\", color=\"type\"), size=4.5)\n    + scale_color_manual(values={\"min\": LOW, \"max\": HIGH, \"endpoint\": INK_MUTED})\n    + labs(title=\"sparkline-basic · python · plotnine · anyplot.ai\")\n    + theme(\n        figure_size=(8, 4.5),\n        # Strip all chart chrome for the pure sparkline aesthetic\n        axis_title=element_blank(),\n        axis_text=element_blank(),\n        axis_ticks=element_blank(),\n        axis_line=element_blank(),\n        panel_grid_major=element_blank(),\n        panel_grid_minor=element_blank(),\n        panel_background=element_rect(fill=PAGE_BG),\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        plot_title=element_text(size=12, ha=\"center\", color=INK),\n        legend_position=\"none\",\n    )\n)\n\n# Save\nplot.save(f\"plot-{THEME}.png\", dpi=400, width=8, height=4.5, units=\"in\", verbose=False)\n"}