{"spec_id":"contour-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\ncontour-basic: Basic Contour Plot\nLibrary: matplotlib 3.11.0 | Python 3.13.14\nQuality: 88/100 | Updated: 2026-06-25\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.colors import LinearSegmentedColormap\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\"\n\n# Imprint sequential colormap for single-polarity elevation data\nimprint_seq = LinearSegmentedColormap.from_list(\"imprint_seq\", [\"#009E73\", \"#4467A3\"])\n\n# Data — simulated topographic elevation of a 20 × 10 km mountain range\n# Northeast summit ~1220 m; southwest summit ~820 m — visible height contrast\nx = np.linspace(0, 20, 120)\ny = np.linspace(0, 10, 60)\nX, Y = np.meshgrid(x, y)\n\nelevation = (\n    900 * np.exp(-((X - 16) ** 2 + (Y - 7.5) ** 2) / 5.0)\n    + 500 * np.exp(-((X - 5) ** 2 + (Y - 3) ** 2) / 4.0)\n    - 100 * np.exp(-((X - 10) ** 2 + (Y - 5) ** 2) / 10.0)\n    + 320\n)\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\nlevels = np.arange(200, 1301, 50)\nmajor_levels = np.arange(400, 1301, 200)\n\nfilled = ax.contourf(X, Y, elevation, levels=levels, cmap=imprint_seq)\nax.contour(X, Y, elevation, levels=levels, colors=INK, linewidths=0.4, alpha=0.30)\nmajor = ax.contour(X, Y, elevation, levels=major_levels, colors=INK, linewidths=0.8, alpha=0.65)\nax.clabel(major, inline=True, fontsize=7, fmt=\"%d m\", inline_spacing=5)\n\n# Summit markers — peak triangles with labeled elevations for data storytelling\nax.plot(16, 7.5, \"^\", color=INK, markersize=4.5, markeredgecolor=PAGE_BG, markeredgewidth=0.5, zorder=5)\nax.annotate(\n    \"NE Summit\\n~1,220 m\",\n    xy=(16, 7.5),\n    xytext=(13.3, 5.2),\n    fontsize=6.5,\n    color=INK,\n    ha=\"center\",\n    va=\"center\",\n    arrowprops={\"arrowstyle\": \"->\", \"color\": INK_SOFT, \"lw\": 0.6, \"mutation_scale\": 6, \"shrinkA\": 0, \"shrinkB\": 5},\n    bbox={\"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.88, \"boxstyle\": \"round,pad=0.3\", \"lw\": 0.5},\n    zorder=6,\n)\n\nax.plot(5, 3, \"^\", color=INK, markersize=4.5, markeredgecolor=PAGE_BG, markeredgewidth=0.5, zorder=5)\nax.annotate(\n    \"SW Summit\\n~815 m\",\n    xy=(5, 3),\n    xytext=(7.8, 5.8),\n    fontsize=6.5,\n    color=INK,\n    ha=\"center\",\n    va=\"center\",\n    arrowprops={\"arrowstyle\": \"->\", \"color\": INK_SOFT, \"lw\": 0.6, \"mutation_scale\": 6, \"shrinkA\": 0, \"shrinkB\": 5},\n    bbox={\"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.88, \"boxstyle\": \"round,pad=0.3\", \"lw\": 0.5},\n    zorder=6,\n)\n\n# Colorbar\ncbar = fig.colorbar(filled, ax=ax, shrink=0.88, aspect=30, pad=0.025)\ncbar.set_label(\"Elevation (m)\", fontsize=10, color=INK)\ncbar.ax.tick_params(labelsize=8, colors=INK_SOFT)\ncbar.outline.set_edgecolor(INK_SOFT)\ncbar.outline.set_linewidth(0.5)\n\n# Style\nax.set_xlabel(\"Distance East (km)\", fontsize=10, color=INK)\nax.set_ylabel(\"Distance North (km)\", fontsize=10, color=INK)\nax.set_title(\"contour-basic · python · matplotlib · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK, pad=10)\nax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT)\nax.set_ylim(-0.3, 10.3)\nfor spine in (\"top\", \"right\"):\n    ax.spines[spine].set_visible(False)\nfor spine in (\"left\", \"bottom\"):\n    ax.spines[spine].set_color(INK_SOFT)\n\nfig.subplots_adjust(left=0.07, right=0.84, top=0.93, bottom=0.11)\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}