{"spec_id":"contour-3d","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\ncontour-3d: 3D Contour Plot\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 95/100 | Updated: 2026-05-16\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Data - Terrain elevation data with realistic features\nnp.random.seed(42)\nx = np.linspace(0, 10, 40)\ny = np.linspace(0, 10, 40)\nX, Y = np.meshgrid(x, y)\n\n# Create realistic terrain with peaks and valleys (elevation in meters)\nZ = 100 + 30 * np.sin(X / 2) * np.cos(Y / 2) + 20 * np.exp(-((X - 5) ** 2 + (Y - 5) ** 2) / 8)\n\n# Create figure with 3D axes\nfig = plt.figure(figsize=(16, 9), facecolor=PAGE_BG)\nax = fig.add_subplot(111, projection=\"3d\", facecolor=PAGE_BG)\nax.xaxis.pane.set_facecolor(PAGE_BG)\nax.yaxis.pane.set_facecolor(PAGE_BG)\nax.zaxis.pane.set_facecolor(PAGE_BG)\n\n# Plot surface with semi-transparency\nsurf = ax.plot_surface(X, Y, Z, cmap=\"viridis\", alpha=0.6, edgecolor=\"none\", antialiased=True)\n\n# Add 3D contour lines on the surface\ncontours = ax.contour(X, Y, Z, levels=12, cmap=\"viridis\", linewidths=2)\n\n# Project contours onto the base plane (z = min)\nz_offset = Z.min() - 5\nax.contour(X, Y, Z, levels=12, zdir=\"z\", offset=z_offset, cmap=\"viridis\", linewidths=1.5)\n\n# Styling - theme-adaptive chrome\nax.set_xlabel(\"Distance East (km)\", fontsize=20, color=INK, labelpad=15)\nax.set_ylabel(\"Distance North (km)\", fontsize=20, color=INK, labelpad=15)\nax.set_zlabel(\"Elevation (m)\", fontsize=20, color=INK, labelpad=15)\nax.set_title(\"contour-3d · matplotlib · anyplot.ai\", fontsize=24, color=INK, pad=20)\n\n# Tick params with theme-adaptive colors\nax.tick_params(axis=\"x\", labelsize=16, colors=INK_SOFT)\nax.tick_params(axis=\"y\", labelsize=16, colors=INK_SOFT)\nax.tick_params(axis=\"z\", labelsize=16, colors=INK_SOFT)\n\n# Set pane edge colors\nax.xaxis.pane.set_edgecolor(INK_SOFT)\nax.yaxis.pane.set_edgecolor(INK_SOFT)\nax.zaxis.pane.set_edgecolor(INK_SOFT)\nax.xaxis.pane.set_alpha(0.1)\nax.yaxis.pane.set_alpha(0.1)\nax.zaxis.pane.set_alpha(0.1)\n\n# Set view angle\nax.view_init(elev=30, azim=45)\n\n# Add colorbar with theme-adaptive colors\ncbar = fig.colorbar(surf, ax=ax, shrink=0.6, aspect=15, pad=0.1)\ncbar.set_label(\"Elevation (m)\", fontsize=16, color=INK)\ncbar.ax.tick_params(labelsize=14, colors=INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}