{"spec_id":"contour-filled","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\ncontour-filled: Filled Contour Plot\nLibrary: plotnine 0.15.4 | Python 3.13.13\nQuality: 88/100 | Updated: 2026-05-11\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import aes, element_line, element_rect, element_text, geom_tile, ggplot, labs, scale_fill_cmap, theme\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# Data - Sinusoidal waves: a distinct pattern different from Gaussian peaks\nx = np.linspace(-2 * np.pi, 2 * np.pi, 80)\ny = np.linspace(-2 * np.pi, 2 * np.pi, 80)\nX, Y = np.meshgrid(x, y)\n\n# Create a wavy surface combining sine and cosine with interference patterns\nZ = (\n    np.sin(X) * np.cos(Y)  # Primary oscillatory pattern\n    + 0.5 * np.sin(2 * X) * np.cos(Y)  # Secondary harmonic\n    + 0.3 * np.cos(3 * Y) * np.sin(X)  # Tertiary component\n)\n\n# Convert to long-format DataFrame for plotnine\ndf = pd.DataFrame({\"x\": X.ravel(), \"y\": Y.ravel(), \"z\": Z.ravel()})\n\n# Custom theme with theme-adaptive chrome\nanyplot_theme = theme(\n    plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n    panel_background=element_rect(fill=PAGE_BG),\n    panel_grid_major=element_line(color=INK, size=0.3, alpha=0.10),\n    panel_grid_minor=element_line(color=INK, size=0.2, alpha=0.05),\n    panel_border=element_rect(color=INK_SOFT, fill=None),\n    axis_title=element_text(color=INK, size=20),\n    axis_text=element_text(color=INK_SOFT, size=16),\n    axis_line=element_line(color=INK_SOFT, size=0.5),\n    plot_title=element_text(color=INK, size=24),\n    legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT),\n    legend_text=element_text(color=INK_SOFT, size=16),\n    legend_title=element_text(color=INK, size=16),\n    figure_size=(16, 9),\n)\n\n# Create filled contour visualization using geom_tile\nplot = (\n    ggplot(df, aes(x=\"x\", y=\"y\", fill=\"z\"))\n    + geom_tile()\n    + scale_fill_cmap(cmap_name=\"BrBG\", name=\"Value\")\n    + labs(x=\"X Coordinate\", y=\"Y Coordinate\", title=\"contour-filled · plotnine · anyplot.ai\")\n    + anyplot_theme\n)\n\n# Save\nplot.save(f\"plot-{THEME}.png\", dpi=300, width=16, height=9)\n"}