{"spec_id":"contour-map-geographic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\ncontour-map-geographic: Contour Lines on Geographic Map\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-20\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\n# Data: Synthetic elevation data over European Alps\nnp.random.seed(42)\n\nlon_min, lon_max = 5.0, 17.0\nlat_min, lat_max = 43.5, 48.5\n\nn_points = 60\nlons = np.linspace(lon_min, lon_max, n_points)\nlats = np.linspace(lat_min, lat_max, n_points)\nlon_grid, lat_grid = np.meshgrid(lons, lats)\n\n# Base undulating terrain\nelevation = 400 + 200 * np.sin(np.radians(lon_grid) * 15) * np.cos(np.radians(lat_grid) * 12)\n\n# Western Alps: Mont Blanc massif (~4808 m peak)\nelevation += 4400 * np.exp(-((lon_grid - 7.0) ** 2) / 3) * np.exp(-((lat_grid - 45.8) ** 2) / 1.5)\n\n# Central Swiss Alps\nelevation += 3600 * np.exp(-((lon_grid - 9.5) ** 2) / 5) * np.exp(-((lat_grid - 46.5) ** 2) / 1.2)\n\n# Austrian Tyrol / Hohe Tauern (Großglockner ~3798 m)\nelevation += 3000 * np.exp(-((lon_grid - 13.0) ** 2) / 4) * np.exp(-((lat_grid - 47.0) ** 2) / 1.5)\n\n# Po Valley lowlands (Italian side — low elevation)\nelevation -= 700 * np.exp(-((lon_grid - 11.0) ** 2) / 20) * np.exp(-((lat_grid - 44.2) ** 2) / 0.8)\n\n# Add noise for realism\nelevation += np.random.normal(0, 80, elevation.shape)\nelevation = np.clip(elevation, 0, None)\n\n# Simplified country border lines\nborders = [\n    {\"lons\": [5.5, 6.5, 7.0, 7.5], \"lats\": [47.5, 47.5, 46.0, 45.8]},\n    {\"lons\": [6.8, 8.0, 10.0, 12.5, 13.8], \"lats\": [45.8, 45.9, 46.0, 46.3, 46.5]},\n    {\"lons\": [8.0, 9.5, 10.5, 12.0, 13.0, 15.0, 17.0], \"lats\": [47.7, 47.6, 47.7, 47.8, 48.0, 48.5, 48.5]},\n    {\"lons\": [13.5, 14.5, 15.5, 16.5], \"lats\": [46.5, 46.3, 46.0, 45.8]},\n]\n\n# Notable peaks to annotate\npeaks = [\n    {\"name\": \"Mont Blanc\\n4808 m\", \"lon\": 6.86, \"lat\": 45.83},\n    {\"name\": \"Matterhorn\\n4478 m\", \"lon\": 7.66, \"lat\": 45.98},\n    {\"name\": \"Großglockner\\n3798 m\", \"lon\": 12.69, \"lat\": 47.07},\n]\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Filled contours using terrain colormap\nlevels = np.arange(0, 5000, 200)\nfilled = ax.contourf(lon_grid, lat_grid, elevation, levels=levels, cmap=\"terrain\", alpha=0.85, extend=\"max\")\n\n# Contour lines every 500 m — heavier weight for high-res visibility\nline_levels = np.arange(500, 5000, 500)\ncontour_lines = ax.contour(lon_grid, lat_grid, elevation, levels=line_levels, colors=INK, linewidths=2.0, alpha=0.45)\nax.clabel(contour_lines, inline=True, fontsize=9, fmt=\"%d m\", colors=INK_MUTED)\n\n# Country border lines\nfor border in borders:\n    ax.plot(border[\"lons\"], border[\"lats\"], color=INK_SOFT, linewidth=1.0, linestyle=\"--\", zorder=4)\n\n# Peak markers and annotations — focal point emphasis\nfor peak in peaks:\n    ax.plot(peak[\"lon\"], peak[\"lat\"], marker=\"^\", markersize=6, color=INK, zorder=6, markeredgewidth=0)\n    ax.annotate(\n        peak[\"name\"],\n        xy=(peak[\"lon\"], peak[\"lat\"]),\n        xytext=(peak[\"lon\"] + 0.25, peak[\"lat\"] - 0.35),\n        fontsize=7,\n        color=INK,\n        fontweight=\"bold\",\n        bbox={\n            \"facecolor\": ELEVATED_BG,\n            \"edgecolor\": INK_SOFT,\n            \"alpha\": 0.85,\n            \"boxstyle\": \"round,pad=0.2\",\n            \"linewidth\": 0.5,\n        },\n        zorder=7,\n    )\n\n# Colorbar — idiomatic fig.colorbar\ncbar = fig.colorbar(filled, ax=ax, orientation=\"vertical\", pad=0.02, shrink=0.88)\ncbar.set_label(\"Elevation (m)\", fontsize=10, color=INK)\ncbar.ax.tick_params(labelsize=8, labelcolor=INK_SOFT)\ncbar.outline.set_edgecolor(INK_SOFT)\n\n# Axis limits and tick formatting\nax.set_xlim(lon_min, lon_max)\nax.set_ylim(lat_min, lat_max)\n\nlon_ticks = np.arange(6, 17, 2)\nax.set_xticks(lon_ticks)\nax.set_xticklabels([f\"{int(x)}°E\" for x in lon_ticks])\n\nlat_ticks = np.arange(44, 49, 1)\nax.set_yticks(lat_ticks)\nax.set_yticklabels([f\"{int(y)}°N\" for y in lat_ticks])\n\nax.tick_params(axis=\"both\", labelsize=8, labelcolor=INK_SOFT)\n\n# Axis labels\nax.set_xlabel(\"Longitude\", fontsize=10, color=INK)\nax.set_ylabel(\"Latitude\", fontsize=10, color=INK)\n\n# Title\nax.set_title(\n    \"contour-map-geographic · python · matplotlib · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK, pad=10\n)\n\n# Spines — keep all four as map border, color-adapt them\nfor spine in ax.spines.values():\n    spine.set_color(INK_SOFT)\n\n# Subtle grid\nax.grid(True, alpha=0.15, linewidth=0.6, color=INK, linestyle=\"--\", zorder=1)\n\nfig.subplots_adjust(left=0.08, right=0.88, top=0.93, bottom=0.12)\n\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\nplt.close()\n"}