{"spec_id":"contour-map-geographic","library":"makie","language":"julia","code":"# anyplot.ai\n# contour-map-geographic: Contour Lines on Geographic Map\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 93/100 | Created: 2026-09-01\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\n# Theme tokens\nconst THEME       = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG     = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst ELEVATED_BG = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\nconst INK         = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT    = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nconst ANYPLOT_SEQ = cgrad([colorant\"#009E73\", colorant\"#4467A3\"])\n\n# Data — synthetic elevation grid over the Cascade Range stratovolcanoes (Washington, USA)\nconst PEAKS = [\n    (name = \"Mount Baker\",      lat = 48.7768, lon = -121.8144, elev = 3286.0),\n    (name = \"Glacier Peak\",     lat = 48.1112, lon = -121.1141, elev = 3213.0),\n    (name = \"Mount Rainier\",    lat = 46.8529, lon = -121.7604, elev = 4392.0),\n    (name = \"Mount Adams\",      lat = 46.2024, lon = -121.4906, elev = 3743.0),\n    (name = \"Mount St. Helens\", lat = 46.1912, lon = -122.1944, elev = 2549.0),\n]\n\nconst lon = range(-123.6, -120.7; length = 72)\nconst lat = range(45.9, 49.1; length = 60)\n\n# Rolling foothill baseline (west→east) plus a Gaussian bump per named summit\nconst z = [\n    250.0 + 350.0 * clamp((lo + 123.2) / 2.5, 0.0, 1.0) +\n    sum((p.elev - 380.0) * exp(-(((lo - p.lon) / 0.22)^2 + ((la - p.lat) / 0.22)^2)) for p in PEAKS)\n    for lo in lon, la in lat\n]\n\nconst LEVELS       = collect(0.0:500.0:4500.0)\nconst LABEL_LEVELS = collect(0.0:500.0:2000.0)  # index contours — the tight rings near each\n                                                 # summit stay unlabeled since the peak marker\n                                                 # already states the exact elevation there\n\n# Puget Sound coastline: a wavy west boundary marking land vs. water\nconst lat_vec   = collect(lat)\nconst coast_lon = @. -123.35 + 0.20 * sin(2.3 * (lat_vec - 45.9)) - 0.05 * cos(4.1 * (lat_vec - 45.9))\n\n# Plot\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"Cascade Range Volcanoes · contour-map-geographic · julia · makie · anyplot.ai\",\n    titlesize          = 17,\n    titlecolor         = INK,\n    xlabel             = \"Longitude\",\n    ylabel             = \"Latitude\",\n    xlabelsize         = 14,\n    ylabelsize         = 14,\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xticklabelsize     = 12,\n    yticklabelsize     = 12,\n    xticklabelcolor    = INK_SOFT,\n    yticklabelcolor    = INK_SOFT,\n    xtickcolor         = INK_SOFT,\n    ytickcolor         = INK_SOFT,\n    xtickformat        = vs -> [\"$(round(abs(v), digits = 1))°W\" for v in vs],\n    ytickformat        = vs -> [\"$(round(v, digits = 1))°N\" for v in vs],\n    backgroundcolor    = PAGE_BG,\n    topspinevisible    = false,\n    rightspinevisible  = false,\n    leftspinecolor     = INK_SOFT,\n    bottomspinecolor   = INK_SOFT,\n    xgridcolor         = RGBAf(INK.r, INK.g, INK.b, 0.12),\n    ygridcolor         = RGBAf(INK.r, INK.g, INK.b, 0.12),\n    limits             = (minimum(lon), maximum(lon), minimum(lat), maximum(lat)),\n)\n\n# Filled elevation contours\ncf = contourf!(ax, lon, lat, z; levels = LEVELS, colormap = ANYPLOT_SEQ)\n\n# Contour lines at every 500 m\ncontour!(ax, lon, lat, z; levels = LEVELS, color = INK, linewidth = 1.0)\n\n# Index contours (every 500 m up to 2000 m) carry the value labels — the\n# tighter rings closer to each summit are left unlabeled to avoid crowding\n# the peak-name labels below\ncontour!(ax, lon, lat, z;\n    levels         = LABEL_LEVELS,\n    color          = INK,\n    linewidth      = 1.4,\n    labels         = true,\n    labelsize      = 11,\n    labelcolor     = INK,\n    labelformatter = level -> \"$(Int(round(level))) m\",\n)\n\n# Mask the water west of the coastline, then stroke the shoreline itself\nwest_edge  = minimum(lon) - 0.3\nwater_poly = vcat(\n    [Point2f(coast_lon[i], lat_vec[i]) for i in eachindex(lat_vec)],\n    [Point2f(west_edge, lat_vec[i]) for i in reverse(eachindex(lat_vec))],\n)\npoly!(ax, water_poly; color = PAGE_BG, strokewidth = 0)\nlines!(ax, coast_lon, lat_vec; color = INK_SOFT, linewidth = 2.5, label = \"Puget Sound coastline\")\n\n# Volcanic summits, labeled with elevation\nscatter!(ax, [p.lon for p in PEAKS], [p.lat for p in PEAKS];\n    marker      = :utriangle,\n    markersize  = 16,\n    color       = INK,\n    strokewidth = 1.5,\n    strokecolor = PAGE_BG,\n    label       = \"Volcanic peak\",\n)\nfor p in PEAKS\n    text!(ax, p.lon, p.lat;\n        text        = \"$(p.name) ($(Int(round(p.elev))) m)\",\n        fontsize    = 12,\n        font        = :bold,\n        color       = INK,\n        strokecolor = PAGE_BG,\n        strokewidth = 1.3,\n        align       = (:center, :bottom),\n        offset      = (0, 14),\n    )\nend\n\naxislegend(ax;\n    position        = :rb,\n    backgroundcolor = ELEVATED_BG,\n    labelcolor      = INK,\n    framecolor      = INK_SOFT,\n    labelsize       = 11,\n)\n\nColorbar(fig[1, 2], cf;\n    label          = \"Elevation (m)\",\n    labelcolor     = INK,\n    labelsize      = 14,\n    tickcolor      = INK_SOFT,\n    ticklabelcolor = INK_SOFT,\n    ticklabelsize  = 12,\n    ticks          = LEVELS,\n    width          = 20,\n)\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}