{"spec_id":"area-basic","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\narea-basic: Basic Area Chart\nLibrary: plotnine 0.15.4 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-28\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    annotate,\n    element_blank,\n    element_line,\n    element_rect,\n    element_text,\n    geom_line,\n    geom_ribbon,\n    geom_smooth,\n    ggplot,\n    labs,\n    scale_x_datetime,\n    scale_y_continuous,\n    theme,\n    theme_minimal,\n)\n\n\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\"\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\", \"#99B314\"]\nBRAND = IMPRINT_PALETTE[0]\n\n# Data\nnp.random.seed(42)\ndates = pd.date_range(start=\"2024-01-01\", periods=31, freq=\"D\")\nbase_traffic = 4800\ntrend = np.linspace(0, 2200, 31)\nweekly_pattern = 1000 * np.sin(np.arange(31) * 2 * np.pi / 7)\namplitude_growth = np.linspace(1.0, 1.8, 31)\nnoise = np.random.normal(0, 500, 31) * amplitude_growth\nvisitors = base_traffic + trend + weekly_pattern * amplitude_growth + noise\nvisitors[14:16] -= np.array([1400, 600])\nvisitors[19:23] = np.mean(visitors[19:23]) * np.ones(4) + np.random.normal(0, 100, 4)\nvisitors = np.maximum(visitors, 1000)\n\ndf = pd.DataFrame({\"date\": dates, \"visitors\": visitors})\n\npeak_idx = int(df[\"visitors\"].idxmax())\npeak_val = int(df[\"visitors\"].max())\ndip_idx = 14\ndip_val = int(df.loc[dip_idx, \"visitors\"])\n\ny_min = int(np.floor(df[\"visitors\"].min() / 500) * 500)\ny_max = int(np.ceil(df[\"visitors\"].max() / 500) * 500) + 500\ndf[\"y_floor\"] = y_min\n\ntitle = \"area-basic · python · plotnine · anyplot.ai\"\nn = len(title)\ntitle_fontsize = max(8, round(12 * (67 / n if n > 67 else 1.0)))\n\n# Plot\nplot = (\n    ggplot(df, aes(x=\"date\", y=\"visitors\"))\n    + geom_ribbon(aes(ymin=\"y_floor\", ymax=\"visitors\"), fill=BRAND, alpha=0.35)\n    + geom_line(color=BRAND, size=1.5)\n    + geom_smooth(method=\"lowess\", color=IMPRINT_PALETTE[2], size=1.5, se=False, span=0.5)\n    + annotate(\n        \"text\",\n        x=dates[peak_idx],\n        y=peak_val + 300,\n        label=f\"Peak: {peak_val:,}\",\n        size=4.0,\n        color=INK,\n        fontweight=\"bold\",\n        ha=\"right\",\n    )\n    + annotate(\n        \"text\",\n        x=dates[dip_idx + 1],\n        y=dip_val + 350,\n        label=f\"Maintenance: {dip_val:,}\",\n        size=3.5,\n        color=INK_MUTED,\n        fontstyle=\"italic\",\n        ha=\"left\",\n    )\n    + annotate(\n        \"text\",\n        x=dates[25],\n        y=df.loc[25, \"visitors\"] + 500,\n        label=\"Trend (LOWESS)\",\n        size=3.5,\n        color=IMPRINT_PALETTE[2],\n        fontweight=\"bold\",\n    )\n    + labs(\n        x=\"Date (January 2024)\",\n        y=\"Daily Visitors (count)\",\n        title=title,\n        subtitle=\"Upward trend with weekly cycles, a mid-month maintenance dip, and a brief plateau\",\n    )\n    + scale_x_datetime(date_labels=\"%b %d\")\n    + scale_y_continuous(labels=lambda lst: [f\"{int(v):,}\" for v in lst], limits=(y_min, y_max))\n    + theme_minimal()\n    + theme(\n        figure_size=(8, 4.5),\n        text=element_text(size=7, color=INK_SOFT),\n        axis_title=element_text(size=10, color=INK),\n        axis_text=element_text(size=8, color=INK_SOFT),\n        plot_title=element_text(size=title_fontsize, weight=\"bold\", color=INK),\n        plot_subtitle=element_text(size=8, color=INK_MUTED, style=\"italic\"),\n        panel_background=element_rect(fill=PAGE_BG, color=\"none\"),\n        plot_background=element_rect(fill=PAGE_BG, color=\"none\"),\n        panel_grid_major_y=element_line(color=INK, size=0.3, alpha=0.15),\n        panel_grid_major_x=element_line(color=INK, size=0.2, alpha=0.08),\n        panel_grid_minor=element_blank(),\n        axis_line_x=element_line(color=INK_SOFT, size=0.6),\n        axis_ticks_major_x=element_line(color=INK_SOFT, size=0.4),\n        axis_ticks_major_y=element_blank(),\n        legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT),\n        legend_text=element_text(color=INK_SOFT),\n        plot_margin=0.04,\n    )\n)\n\nplot.save(f\"plot-{THEME}.png\", dpi=400, width=8, height=4.5, units=\"in\", verbose=False)\n"}