{"spec_id":"scatter-3d","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nscatter-3d: 3D Scatter Plot\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 85/100 | Updated: 2026-05-08\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport plotly.graph_objects as go\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 - Molecular compound properties (3D chemical space)\nnp.random.seed(42)\n\n# Three distinct clusters representing different compound families\n# X: Molecular Weight (g/mol), Y: LogP (lipophilicity), Z: Tpsa (polar surface area)\ncluster1_x = np.random.normal(320, 40, 50)  # Heavy molecules\ncluster1_y = np.random.normal(3.5, 0.8, 50)\ncluster1_z = np.random.normal(60, 15, 50)\n\ncluster2_x = np.random.normal(180, 30, 50)  # Light molecules\ncluster2_y = np.random.normal(1.2, 0.6, 50)\ncluster2_z = np.random.normal(40, 10, 50)\n\ncluster3_x = np.random.normal(250, 35, 50)  # Medium molecules\ncluster3_y = np.random.normal(2.8, 0.7, 50)\ncluster3_z = np.random.normal(80, 12, 50)\n\nx = np.concatenate([cluster1_x, cluster2_x, cluster3_x])\ny = np.concatenate([cluster1_y, cluster2_y, cluster3_y])\nz = np.concatenate([cluster1_z, cluster2_z, cluster3_z])\n\n# Use molecular weight for color (continuous dimension)\ncolor = x\n\n# Create 3D scatter plot with turbo colormap for library differentiation\nfig = go.Figure(\n    data=[\n        go.Scatter3d(\n            x=x,\n            y=y,\n            z=z,\n            mode=\"markers\",\n            marker=dict(\n                size=12,\n                color=color,\n                colorscale=\"Turbo\",\n                opacity=0.8,\n                colorbar=dict(\n                    title=dict(text=\"Molecular Weight (g/mol)\", font=dict(size=22)),\n                    tickfont=dict(size=16),\n                    thickness=25,\n                    len=0.7,\n                    x=1.02,\n                    xpad=15,\n                ),\n            ),\n            hovertemplate=\"<b>Compound Analysis</b><br>\"\n            \"Molecular Weight: %{marker.color:.1f} g/mol<br>\"\n            \"LogP (Lipophilicity): %{y:.2f}<br>\"\n            \"Polar Surface Area: %{z:.1f} Ų<br>\"\n            \"<extra></extra>\",\n        )\n    ]\n)\n\n# Update layout with theme-adaptive styling\nfig.update_layout(\n    title=dict(text=\"scatter-3d · plotly · anyplot.ai\", font=dict(size=32, color=INK), x=0.5, xanchor=\"center\"),\n    scene=dict(\n        xaxis=dict(\n            title=dict(text=\"Molecular Weight (g/mol)\", font=dict(size=22, color=INK)),\n            tickfont=dict(size=16, color=INK_SOFT),\n            gridcolor=\"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\",\n            showbackground=True,\n            backgroundcolor=PAGE_BG,\n        ),\n        yaxis=dict(\n            title=dict(text=\"LogP (Lipophilicity)\", font=dict(size=22, color=INK)),\n            tickfont=dict(size=16, color=INK_SOFT),\n            gridcolor=\"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\",\n            showbackground=True,\n            backgroundcolor=PAGE_BG,\n        ),\n        zaxis=dict(\n            title=dict(text=\"Polar Surface Area (Ų)\", font=dict(size=22, color=INK)),\n            tickfont=dict(size=16, color=INK_SOFT),\n            gridcolor=\"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\",\n            showbackground=True,\n            backgroundcolor=PAGE_BG,\n        ),\n        camera=dict(eye=dict(x=1.5, y=1.5, z=1.2)),\n        bgcolor=PAGE_BG,\n    ),\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font=dict(color=INK),\n    margin=dict(l=60, r=100, t=120, b=60),\n)\n\n# Save outputs (theme-suffixed filenames)\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}