{"spec_id":"contour-basic","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\ncontour-basic: Basic Contour Plot\nLibrary: plotly 6.8.0 | Python 3.13.14\nQuality: 91/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport plotly.graph_objects as go\n\n\n# Theme tokens — Imprint palette chrome\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.15)\" if THEME == \"light\" else \"rgba(240,239,232,0.15)\"\n\n# Imprint diverging colormap: matte-red (low) → PAGE_BG (zero) → blue (high)\nmidpoint = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nimprint_div = [[0.0, \"#AE3030\"], [0.5, midpoint], [1.0, \"#4467A3\"]]\n\n# Data — regional surface pressure anomaly (hPa deviation from 1013 hPa)\nlon = np.linspace(-6, 6, 90)  # longitude offset (°E)\nlat = np.linspace(-4, 4, 70)  # latitude offset (°N)\nLON, LAT = np.meshgrid(lon, lat)\n\nanticyclone = 14.0 * np.exp(-((LON + 2.5) ** 2 / 4.0 + LAT**2 / 2.5))\ncyclone = -12.0 * np.exp(-((LON - 2.5) ** 2 / 3.5 + LAT**2 / 2.0))\npressure_anomaly = anticyclone + cyclone\n\n# Title fontsize scaled by character count\ntitle = \"contour-basic · python · plotly · anyplot.ai\"\ntitle_fontsize = round(16 * (67 / len(title) if len(title) > 67 else 1.0))\n\n# Plot\nfig = go.Figure()\n\nfig.add_trace(\n    go.Contour(\n        x=lon,\n        y=lat,\n        z=pressure_anomaly,\n        colorscale=imprint_div,\n        zmid=0,\n        contours={\n            \"showlabels\": True,\n            \"labelfont\": {\"size\": 10, \"color\": INK},\n            \"coloring\": \"fill\",\n            \"start\": -14,\n            \"end\": 14,\n            \"size\": 2,\n        },\n        colorbar={\n            \"title\": {\"text\": \"Pressure Anomaly (hPa)\", \"font\": {\"size\": 12, \"color\": INK}, \"side\": \"right\"},\n            \"tickfont\": {\"size\": 10, \"color\": INK_SOFT},\n            \"thickness\": 18,\n            \"len\": 0.85,\n            \"bgcolor\": ELEVATED_BG,\n            \"bordercolor\": INK_SOFT,\n            \"borderwidth\": 1,\n        },\n        line={\"width\": 1.5, \"color\": INK_SOFT},\n    )\n)\n\nfig.update_layout(\n    autosize=False,\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    title={\"text\": title, \"font\": {\"size\": title_fontsize, \"color\": INK}, \"x\": 0.5, \"xanchor\": \"center\"},\n    xaxis={\n        \"title\": {\"text\": \"Longitude Offset (°E)\", \"font\": {\"size\": 12, \"color\": INK}},\n        \"tickfont\": {\"size\": 10, \"color\": INK_SOFT},\n        \"gridcolor\": GRID,\n        \"linecolor\": INK_SOFT,\n        \"zerolinecolor\": GRID,\n    },\n    yaxis={\n        \"title\": {\"text\": \"Latitude Offset (°N)\", \"font\": {\"size\": 12, \"color\": INK}},\n        \"tickfont\": {\"size\": 10, \"color\": INK_SOFT},\n        \"gridcolor\": GRID,\n        \"linecolor\": INK_SOFT,\n        \"zerolinecolor\": GRID,\n    },\n    margin={\"l\": 80, \"r\": 100, \"t\": 80, \"b\": 60},\n    font={\"color\": INK},\n)\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=800, height=450, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}