{"spec_id":"surface-basic","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nsurface-basic: Basic 3D Surface Plot\nLibrary: pygal 3.1.0 | Python 3.13.13\nQuality: 74/100 | Created: 2026-05-05\n\"\"\"\n\nimport os\nimport pathlib\nimport sys\nscript_dir = str(pathlib.Path(__file__).parent)\nsys.path = [p for p in sys.path if p != script_dir and p != \".\"]\n\nimport numpy as np\nimport pygal\nfrom matplotlib.colors import Normalize\nfrom pygal.style import Style\n\n\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\n\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\nIMPRINT = (\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\")\n\ncustom_style = Style(\n    background=PAGE_BG,\n    plot_background=PAGE_BG,\n    foreground=INK,\n    foreground_strong=INK,\n    foreground_subtle=INK_MUTED,\n    colors=IMPRINT,\n    title_font_size=28,\n    label_font_size=22,\n    major_label_font_size=18,\n    legend_font_size=16,\n    value_font_size=14,\n    stroke_width=2,\n)\n\nnp.random.seed(42)\nx = np.linspace(-5, 5, 35)\ny = np.linspace(-5, 5, 35)\nX, Y = np.meshgrid(x, y)\nZ = np.sin(np.sqrt(X**2 + Y**2)) * np.cos(X * 0.5)\n\nz_min, z_max = Z.min(), Z.max()\nnorm = Normalize(vmin=z_min, vmax=z_max)\n\nz_binned = (norm(Z.flatten()) * 6).astype(int)\nz_binned = np.clip(z_binned, 0, 6)\n\nxy_pairs = list(zip(X.flatten(), Y.flatten(), z_binned, strict=False))\n\nchart = pygal.XY(\n    style=custom_style,\n    width=4800,\n    height=2700,\n    title=\"surface-basic · pygal · anyplot.ai\",\n    x_title=\"X Axis\",\n    y_title=\"Y Axis\",\n    show_legend=True,\n    dots_size=6,\n    stroke=False,\n)\n\nfor bin_idx in range(7):\n    points = [(x, y) for x, y, z in xy_pairs if z == bin_idx]\n    if points:\n        chart.add(f\"Height {bin_idx}\", points)\n\nchart.render_to_png(f\"plot-{THEME}.png\")\nwith open(f\"plot-{THEME}.html\", \"wb\") as f:\n    f.write(chart.render())\n"}