{"spec_id":"scatter-3d","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nscatter-3d: 3D Scatter Plot\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 89/100 | Updated: 2026-05-08\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 - Simulate protein structure analysis with 3D atomic coordinates\n# Representing different protein domains with distinct spatial clustering\nnp.random.seed(42)\n\n# Domain 1: Alpha helix region (lower left)\nn1 = 60\nx1 = np.random.randn(n1) * 1.5 + 2\ny1 = np.random.randn(n1) * 1.5 + 2\nz1 = np.random.randn(n1) * 1.5 + 2\n\n# Domain 2: Beta sheet region (upper right)\nn2 = 50\nx2 = np.random.randn(n2) * 1.2 + 7\ny2 = np.random.randn(n2) * 1.2 + 7\nz2 = np.random.randn(n2) * 1.2 + 7\n\n# Domain 3: Loop region (middle-high)\nn3 = 40\nx3 = np.random.randn(n3) * 1.0 + 5\ny3 = np.random.randn(n3) * 1.0 + 4\nz3 = np.random.randn(n3) * 1.0 + 9\n\n# Combine all domains\nx = np.concatenate([x1, x2, x3])\ny = np.concatenate([y1, y2, y3])\nz = np.concatenate([z1, z2, z3])\n\n# Color based on z-value (representing depth/elevation in Angstroms)\ncolors = z\n\n# Create 3D plot\nfig = plt.figure(figsize=(16, 9), facecolor=PAGE_BG)\nax = fig.add_subplot(111, projection=\"3d\")\nax.set_facecolor(PAGE_BG)\n\n# Scatter plot with color encoding\nscatter = ax.scatter(x, y, z, c=colors, cmap=\"viridis\", s=120, alpha=0.7, edgecolors=PAGE_BG, linewidth=0.5)\n\n# Add colorbar with improved positioning\ncbar = fig.colorbar(scatter, ax=ax, shrink=0.65, aspect=25, pad=0.08)\ncbar.set_label(\"Elevation (Å)\", fontsize=18, color=INK)\ncbar.ax.tick_params(labelsize=14, colors=INK_SOFT, labelcolor=INK_SOFT)\n\n# Labels with realistic scientific context (molecular coordinates in Angstroms)\nax.set_xlabel(\"X Coordinate (Å)\", fontsize=20, labelpad=15, color=INK)\nax.set_ylabel(\"Y Coordinate (Å)\", fontsize=20, labelpad=15, color=INK)\nax.set_zlabel(\"Z Coordinate (Å)\", fontsize=20, labelpad=15, color=INK)\nax.set_title(\"scatter-3d · matplotlib · anyplot.ai\", fontsize=24, pad=20, color=INK)\n\n# Tick parameters\nax.tick_params(axis=\"x\", labelsize=16, colors=INK_SOFT, labelcolor=INK_SOFT)\nax.tick_params(axis=\"y\", labelsize=16, colors=INK_SOFT, labelcolor=INK_SOFT)\nax.tick_params(axis=\"z\", labelsize=16, colors=INK_SOFT, labelcolor=INK_SOFT)\n\n# Subtle grid lines for 3D space judgment\nax.grid(True, alpha=0.15, linewidth=0.8, color=INK_SOFT)\n\n# Set viewing angle for better visualization\nax.view_init(elev=25, azim=45)\n\n# Subtle pane styling\nax.xaxis.pane.fill = False\nax.yaxis.pane.fill = False\nax.zaxis.pane.fill = False\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.15)\nax.yaxis.pane.set_alpha(0.15)\nax.zaxis.pane.set_alpha(0.15)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}