{"spec_id":"contour-filled","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\ncontour-filled: Filled Contour Plot\nLibrary: letsplot 4.9.0 | Python 3.13.13\nQuality: 89/100 | Updated: 2026-05-11\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom lets_plot import (\n    LetsPlot,\n    aes,\n    element_rect,\n    element_text,\n    geom_contour,\n    geom_contourf,\n    ggplot,\n    ggsize,\n    labs,\n    scale_fill_viridis,\n    theme,\n    theme_minimal,\n)\nfrom lets_plot.export import ggsave\n\n\nLetsPlot.setup_html()\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# Data - Topographic elevation map\nnp.random.seed(42)\nn_points = 60\n\n# Coordinates in km (realistic geographic scale)\nx = np.linspace(0, 50, n_points)\ny = np.linspace(0, 50, n_points)\nX, Y = np.meshgrid(x, y)\n\n# Elevation model in meters - multiple peaks simulating mountain ranges\n# Main peak (2500m) at position (15, 20)\npeak1 = 2500 * np.exp(-((X - 15) ** 2 + (Y - 20) ** 2) / 50)\n# Secondary peak (1800m) at position (35, 35)\npeak2 = 1800 * np.exp(-((X - 35) ** 2 + (Y - 35) ** 2) / 40)\n# Valley depression (800m baseline with deeper valley)\nvalley = 800 - 600 * np.exp(-((X - 25) ** 2 + (Y - 10) ** 2) / 60)\n# Ridge formation along diagonal\nridge = 400 * np.exp(-((X - Y) ** 2) / 100)\n\nZ = peak1 + peak2 + valley + ridge\nZ = np.maximum(Z, 100)  # Floor at 100m elevation\n\n# Convert to long-form DataFrame for lets-plot\ndf = pd.DataFrame({\"longitude_km\": X.flatten(), \"latitude_km\": Y.flatten(), \"elevation_m\": Z.flatten()})\n\n# Create filled contour plot with smooth color bands\nplot = (\n    ggplot(df, aes(x=\"longitude_km\", y=\"latitude_km\", z=\"elevation_m\"))\n    + geom_contourf(aes(fill=\"..level..\"), bins=15)\n    + geom_contour(color=\"white\", size=0.4, alpha=0.5, bins=15)\n    + scale_fill_viridis(name=\"Elevation (m)\", option=\"plasma\")\n    + labs(x=\"Longitude (km)\", y=\"Latitude (km)\", title=\"contour-filled · letsplot · anyplot.ai\")\n    + theme_minimal()\n    + theme(\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG),\n        axis_title=element_text(size=20, color=INK),\n        axis_text=element_text(size=16, color=INK_SOFT),\n        plot_title=element_text(size=24, color=INK),\n        legend_text=element_text(size=14, color=INK_SOFT),\n        legend_title=element_text(size=16, color=INK),\n        legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT),\n    )\n    + ggsize(1600, 900)\n)\n\n# Save PNG (scale=3 gives 4800x2700)\nggsave(plot, f\"plot-{THEME}.png\", path=\".\", scale=3)\n\n# Save HTML for interactivity\nggsave(plot, f\"plot-{THEME}.html\", path=\".\")\n"}