{"spec_id":"line-confidence","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nline-confidence: Line Plot with Confidence Interval\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 94/100 | Updated: 2026-05-09\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport plotly.graph_objects as go\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\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1 — ALWAYS first series\n\n# Data - Monthly temperature forecast with 95% confidence interval\nnp.random.seed(42)\n\n# Generate 50 months of data\nmonths = np.arange(1, 51)\n\n# Create a realistic temperature trend with seasonality\nbase_trend = 15 + 0.05 * months  # Slight warming trend\nseasonality = 8 * np.sin(2 * np.pi * months / 12)  # Annual cycle\nnoise = np.random.normal(0, 1.5, len(months))\n\n# Central temperature values (mean forecast)\ntemperature_mean = base_trend + seasonality + noise\n\n# Confidence interval widens slightly over time (uncertainty grows)\nuncertainty = 1.5 + 0.03 * months\ny_lower = temperature_mean - 1.96 * uncertainty\ny_upper = temperature_mean + 1.96 * uncertainty\n\n# Create figure\nfig = go.Figure()\n\n# Add confidence band (shaded area) with custom hover\nband_color = f\"rgba({int(BRAND[1:3], 16)}, {int(BRAND[3:5], 16)}, {int(BRAND[5:7], 16)}, 0.25)\"\nfig.add_trace(\n    go.Scatter(\n        x=np.concatenate([months, months[::-1]]),\n        y=np.concatenate([y_upper, y_lower[::-1]]),\n        fill=\"toself\",\n        fillcolor=band_color,\n        line=dict(color=\"rgba(255, 255, 255, 0)\"),\n        hovertemplate=\"<b>95% CI</b><br>Month: %{x:.0f}<extra></extra>\",\n        showlegend=True,\n        name=\"95% Confidence Interval\",\n    )\n)\n\n# Add central line (mean) with custom hover\nfig.add_trace(\n    go.Scatter(\n        x=months,\n        y=temperature_mean,\n        mode=\"lines\",\n        line=dict(color=BRAND, width=4),\n        hovertemplate=\"<b>Mean Temperature</b><br>Month: %{x:.0f}<br>Temp: %{y:.1f}°C<extra></extra>\",\n        name=\"Mean Temperature\",\n    )\n)\n\n# Update layout for large canvas with theme-adaptive colors\nfig.update_layout(\n    title=dict(text=\"line-confidence · plotly · anyplot.ai\", font=dict(size=28, color=INK), x=0.5, xanchor=\"center\"),\n    xaxis=dict(\n        title=dict(text=\"Month\", font=dict(size=22, color=INK)),\n        tickfont=dict(size=18, color=INK_SOFT),\n        gridcolor=GRID,\n        gridwidth=1,\n        showgrid=True,\n        linecolor=INK_SOFT,\n        zerolinecolor=INK_SOFT,\n    ),\n    yaxis=dict(\n        title=dict(text=\"Temperature (°C)\", font=dict(size=22, color=INK)),\n        tickfont=dict(size=18, color=INK_SOFT),\n        gridcolor=GRID,\n        gridwidth=1,\n        showgrid=True,\n        linecolor=INK_SOFT,\n        zerolinecolor=INK_SOFT,\n    ),\n    legend=dict(\n        font=dict(size=18, color=INK_SOFT),\n        x=0.98,\n        y=0.98,\n        xanchor=\"right\",\n        yanchor=\"top\",\n        bgcolor=ELEVATED_BG,\n        bordercolor=INK_SOFT,\n        borderwidth=1,\n    ),\n    template=\"plotly_white\",\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    margin=dict(l=100, r=60, t=100, b=80),\n)\n\n# Save as PNG (4800 × 2700 px)\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\n\n# Save as HTML for interactivity\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}