{"spec_id":"contour-filled","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\ncontour-filled: Filled Contour Plot\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 93/100 | Updated: 2026-05-11\n\"\"\"\n\nimport os\nimport sys\n\nimport numpy as np\n\n\n# Ensure plotly module is imported from site-packages, not local file\nfor p in sys.path[:]:\n    if p.endswith(\"python\") and \"contour-filled\" in p:\n        sys.path.remove(p)\n\nfrom plotly import graph_objects as go\n\n\n# Theme tokens\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)\"\n\n# Data - Create a meshgrid with multiple Gaussian peaks for interesting contours\nnp.random.seed(42)\nx = np.linspace(-3, 3, 100)\ny = np.linspace(-3, 3, 100)\nX, Y = np.meshgrid(x, y)\n\n# Create surface with multiple Gaussian peaks and a saddle point\nz1 = 2 * np.exp(-((X - 1) ** 2 + (Y - 1) ** 2))\nz2 = 1.5 * np.exp(-((X + 1) ** 2 + (Y + 1) ** 2))\nz3 = -1 * np.exp(-((X - 1) ** 2 + (Y + 1) ** 2))\nz4 = 0.5 * np.exp(-((X + 1.5) ** 2 + (Y - 1.5) ** 2))\nZ = z1 + z2 + z3 + z4\n\n# Create filled contour plot with enhanced visualization\nfig = go.Figure()\n\n# Custom diverging colorscale for more sophisticated aesthetics\nfig.add_trace(\n    go.Contour(\n        x=x,\n        y=y,\n        z=Z,\n        colorscale=\"RdBu_r\",\n        contours=dict(\n            coloring=\"heatmap\",\n            showlabels=True,\n            labelfont=dict(size=16, color=\"white\", family=\"Arial\"),\n            labelformat=\".2f\",\n        ),\n        colorbar=dict(\n            title=dict(text=\"Surface Value\", font=dict(size=20, color=INK, family=\"Arial\")),\n            tickfont=dict(size=16, color=INK_SOFT, family=\"Arial\"),\n            thickness=28,\n            len=0.85,\n            x=1.02,\n            bgcolor=ELEVATED_BG,\n            bordercolor=INK_SOFT,\n            borderwidth=2,\n        ),\n        ncontours=18,\n        line=dict(width=1.5, color=\"white\"),\n        hovertemplate=\"<b>Position</b><br>X: %{x:.2f}<br>Y: %{y:.2f}<br><b>Value: %{z:.3f}</b><extra></extra>\",\n        name=\"Surface\",\n    )\n)\n\n# Overlay scatter points at the peak locations for visual emphasis\npeak_locations = np.array([[1, 1], [-1, -1], [1.5, -1.5]])\npeak_values = np.array([2.0, 1.5, 0.5])\nfig.add_trace(\n    go.Scatter(\n        x=peak_locations[:, 0],\n        y=peak_locations[:, 1],\n        mode=\"markers\",\n        marker=dict(size=14, color=\"white\", line=dict(color=INK, width=2), symbol=\"star\"),\n        hovertemplate=\"<b>Peak</b><br>X: %{x:.2f}<br>Y: %{y:.2f}<extra></extra>\",\n        name=\"Peaks\",\n        showlegend=True,\n    )\n)\n\n# Update layout for large canvas with theme-adaptive colors\nfig.update_layout(\n    title=dict(\n        text=\"contour-filled · plotly · anyplot.ai\",\n        font=dict(size=28, color=INK, family=\"Arial\", weight=\"bold\"),\n        x=0.5,\n        xanchor=\"center\",\n        y=0.98,\n        yanchor=\"top\",\n    ),\n    xaxis=dict(\n        title=dict(text=\"X Position\", font=dict(size=22, color=INK, family=\"Arial\")),\n        tickfont=dict(size=18, color=INK_SOFT, family=\"Arial\"),\n        showgrid=True,\n        gridwidth=1,\n        gridcolor=GRID,\n        linecolor=INK_SOFT,\n        zerolinecolor=INK_SOFT,\n        zeroline=True,\n    ),\n    yaxis=dict(\n        title=dict(text=\"Y Position\", font=dict(size=22, color=INK, family=\"Arial\")),\n        tickfont=dict(size=18, color=INK_SOFT, family=\"Arial\"),\n        showgrid=True,\n        gridwidth=1,\n        gridcolor=GRID,\n        linecolor=INK_SOFT,\n        zerolinecolor=INK_SOFT,\n        zeroline=True,\n        scaleanchor=\"x\",\n        scaleratio=1,\n    ),\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    margin=dict(l=100, r=140, t=100, b=100),\n    legend=dict(\n        x=0.02,\n        y=0.98,\n        bgcolor=\"rgba(255,255,255,0)\" if THEME == \"light\" else \"rgba(0,0,0,0)\",\n        bordercolor=INK_SOFT,\n        borderwidth=0,\n        font=dict(size=14, color=INK_SOFT, family=\"Arial\"),\n    ),\n    hovermode=\"closest\",\n)\n\n# Save as PNG and HTML with theme suffix\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}