{"spec_id":"map-route-path","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nmap-route-path: Route Path Map\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 87/100 | Updated: 2026-05-21\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\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\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1 — always first series\n\nsns.set_theme(\n    style=\"ticks\",\n    rc={\n        \"figure.facecolor\": PAGE_BG,\n        \"axes.facecolor\": PAGE_BG,\n        \"axes.edgecolor\": INK_SOFT,\n        \"axes.labelcolor\": INK,\n        \"text.color\": INK,\n        \"xtick.color\": INK_SOFT,\n        \"ytick.color\": INK_SOFT,\n        \"grid.color\": INK,\n        \"grid.alpha\": 0.10,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Data — mountain bike trail GPS track near Crested Butte, Colorado\nnp.random.seed(42)\nn_points = 250\n\nstart_lat, start_lon = 38.870, -106.985\n\nlat_steps = np.random.normal(0.0003, 0.0002, n_points)\nlon_steps = np.random.normal(0.0004, 0.0003, n_points)\nlat_steps[:80] += 0.00025\nlon_steps[:80] += 0.00015\nlat_steps[80:160] += 0.00010\nlon_steps[80:160] -= 0.00020\nlat_steps[160:] -= 0.00030\nlon_steps[160:] += 0.00010\n\nlats = start_lat + np.cumsum(lat_steps)\nlons = start_lon + np.cumsum(lon_steps)\n\nbase_elev = 2820\nelevation = (\n    base_elev + np.cumsum(np.random.normal(0.8, 3.5, n_points)) + 120 * np.sin(np.linspace(0, 1.8 * np.pi, n_points))\n)\n\nelapsed_min = np.linspace(0, 150, n_points)\n\ndf = pd.DataFrame({\"lat\": lats, \"lon\": lons, \"elapsed_min\": elapsed_min, \"elevation_m\": elevation})\n\n# Figure: route map (top) + elevation profile (bottom)\nfig, (ax_map, ax_elev) = plt.subplots(\n    2, 1, figsize=(8, 4.5), dpi=400, gridspec_kw={\"height_ratios\": [3, 1]}, facecolor=PAGE_BG\n)\nfig.subplots_adjust(left=0.08, right=0.90, top=0.93, bottom=0.10, hspace=0.55)\nax_map.set_facecolor(PAGE_BG)\nax_elev.set_facecolor(PAGE_BG)\n\n# Connecting path — strong line for clear route continuity\nsns.lineplot(data=df, x=\"lon\", y=\"lat\", color=INK_SOFT, linewidth=2.8, alpha=0.75, ax=ax_map, sort=False, zorder=1)\n\n# Waypoints colored by elapsed time (viridis — perceptually uniform sequential)\nsc = ax_map.scatter(\n    df[\"lon\"], df[\"lat\"], c=df[\"elapsed_min\"], cmap=\"viridis\", s=20, alpha=0.9, zorder=2, edgecolors=\"none\"\n)\n\n# Start — Okabe-Ito position 1 (brand green)\nax_map.scatter(\n    df[\"lon\"].iloc[0],\n    df[\"lat\"].iloc[0],\n    c=BRAND,\n    s=300,\n    marker=\"o\",\n    edgecolors=PAGE_BG,\n    linewidths=2,\n    zorder=5,\n    label=\"Start\",\n)\n\n# End — Okabe-Ito position 2 (vermillion) — larger to distinguish from dense viridis cluster\nax_map.scatter(\n    df[\"lon\"].iloc[-1],\n    df[\"lat\"].iloc[-1],\n    c=\"#C475FD\",\n    s=400,\n    marker=\"s\",\n    edgecolors=PAGE_BG,\n    linewidths=2,\n    zorder=5,\n    label=\"End\",\n)\n\n# Direction arrows along the path\nfor idx in [50, 100, 150, 200]:\n    ax_map.annotate(\n        \"\",\n        xy=(df[\"lon\"].iloc[idx + 1], df[\"lat\"].iloc[idx + 1]),\n        xytext=(df[\"lon\"].iloc[idx], df[\"lat\"].iloc[idx]),\n        arrowprops={\"arrowstyle\": \"->\", \"color\": INK_SOFT, \"lw\": 1.5},\n        zorder=3,\n    )\n\n# Colorbar for elapsed time\ncbar = plt.colorbar(sc, ax=ax_map, pad=0.02, fraction=0.035)\ncbar.set_label(\"Elapsed Time (min)\", fontsize=8, color=INK)\ncbar.ax.tick_params(labelsize=8, colors=INK_SOFT)\ncbar.outline.set_edgecolor(INK_SOFT)\n\nax_map.set_xlabel(\"Longitude (°)\", fontsize=10, color=INK)\nax_map.set_ylabel(\"Latitude (°)\", fontsize=10, color=INK)\nax_map.set_title(\n    \"Colorado Mountain Bike Trail  ·  map-route-path · python · seaborn · anyplot.ai\",\n    fontsize=11,\n    fontweight=\"medium\",\n    color=INK,\n)\nax_map.tick_params(axis=\"both\", labelsize=8)\nax_map.legend(fontsize=8, loc=\"upper right\", framealpha=0.9)\nsns.despine(ax=ax_map)\n\n# Elevation profile — seaborn lineplot with fill for area under curve\nsns.lineplot(data=df, x=\"elapsed_min\", y=\"elevation_m\", color=BRAND, linewidth=2.2, ax=ax_elev)\nax_elev.fill_between(df[\"elapsed_min\"], df[\"elevation_m\"].min() - 5, df[\"elevation_m\"], alpha=0.15, color=BRAND)\n\nax_elev.set_xlabel(\"Elapsed Time (min)\", fontsize=9, color=INK)\nax_elev.set_ylabel(\"Elevation (m)\", fontsize=9, color=INK)\nax_elev.tick_params(axis=\"both\", labelsize=7)\nax_elev.yaxis.grid(True, alpha=0.10, linewidth=0.8)\nsns.despine(ax=ax_elev)\n\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}