{"spec_id":"line-3d-trajectory","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nline-3d-trajectory: 3D Line Plot for Trajectory Visualization\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 96/100 | Updated: 2026-05-16\n\"\"\"\n\nimport os\nimport sys\n\nimport numpy as np\n\n\n# Avoid shadowing plotly package when script is named plotly.py\nwhile sys.path and (sys.path[0] == \"\" or sys.path[0].endswith(\"/python\")):\n    sys.path.pop(0)\n\nimport plotly.graph_objects as go\n\n\n# Theme tokens (see prompts/default-style-guide.md \"Background\" + \"Theme-adaptive Chrome\")\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\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\n\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\"]\n\n# Data: Multiple 3D helix trajectories with different periods and amplitudes\nnp.random.seed(42)\n\n# Parameters for three helical trajectories\ntrajectories = []\nlabels = []\n\n# Helix 1: Standard helix\nt1 = np.linspace(0, 8 * np.pi, 500)\nx1 = 5 * np.cos(t1)\ny1 = 5 * np.sin(t1)\nz1 = 3 * t1 / (8 * np.pi)\ntrajectories.append((x1, y1, z1, IMPRINT[0]))\nlabels.append(\"Standard Helix\")\n\n# Helix 2: Compressed helix (faster rise, tighter spiral)\nt2 = np.linspace(0, 6 * np.pi, 400)\nx2 = 3.5 * np.cos(2 * t2)\ny2 = 3.5 * np.sin(2 * t2)\nz2 = 5 * t2 / (6 * np.pi)\ntrajectories.append((x2, y2, z2, IMPRINT[1]))\nlabels.append(\"Compressed Helix\")\n\n# Helix 3: Expanding helix (amplitude increases with height)\nt3 = np.linspace(0, 4 * np.pi, 400)\namplitude = 2 + 3 * (t3 / (4 * np.pi))\nx3 = amplitude * np.cos(t3)\ny3 = amplitude * np.sin(t3)\nz3 = 6 * t3 / (4 * np.pi)\ntrajectories.append((x3, y3, z3, IMPRINT[2]))\nlabels.append(\"Expanding Helix\")\n\n# Create 3D line plot with multiple trajectories\nfig = go.Figure()\n\nfor (x, y, z, color), label in zip(trajectories, labels, strict=True):\n    fig.add_trace(\n        go.Scatter3d(\n            x=x,\n            y=y,\n            z=z,\n            mode=\"lines\",\n            name=label,\n            line=dict(color=color, width=6),\n            hovertemplate=f\"{label}<br>X: %{{x:.2f}}<br>Y: %{{y:.2f}}<br>Z: %{{z:.2f}}<extra></extra>\",\n        )\n    )\n\n# Update layout for 4800x2700 output\nfig.update_layout(\n    title=dict(\n        text=\"Multiple Helical Trajectories · line-3d-trajectory · plotly · anyplot.ai\",\n        font=dict(size=28, color=INK),\n        x=0.5,\n        xanchor=\"center\",\n    ),\n    scene=dict(\n        xaxis=dict(\n            title=dict(text=\"X Position\", font=dict(size=22, color=INK)),\n            tickfont=dict(size=18, color=INK_SOFT),\n            gridcolor=GRID,\n            showbackground=True,\n            backgroundcolor=PAGE_BG,\n            linecolor=INK_SOFT,\n            zerolinecolor=INK_SOFT,\n        ),\n        yaxis=dict(\n            title=dict(text=\"Y Position\", font=dict(size=22, color=INK)),\n            tickfont=dict(size=18, color=INK_SOFT),\n            gridcolor=GRID,\n            showbackground=True,\n            backgroundcolor=PAGE_BG,\n            linecolor=INK_SOFT,\n            zerolinecolor=INK_SOFT,\n        ),\n        zaxis=dict(\n            title=dict(text=\"Z Position\", font=dict(size=22, color=INK)),\n            tickfont=dict(size=18, color=INK_SOFT),\n            gridcolor=GRID,\n            showbackground=True,\n            backgroundcolor=PAGE_BG,\n            linecolor=INK_SOFT,\n            zerolinecolor=INK_SOFT,\n        ),\n        camera=dict(eye=dict(x=1.5, y=1.5, z=1.2)),\n        aspectmode=\"data\",\n    ),\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font=dict(color=INK),\n    legend=dict(\n        x=0.02, y=0.98, bgcolor=ELEVATED_BG, bordercolor=INK_SOFT, borderwidth=1, font=dict(size=18, color=INK_SOFT)\n    ),\n    margin=dict(l=20, r=20, t=100, b=20),\n    hovermode=\"closest\",\n)\n\n# Save as PNG (4800x2700) and HTML\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}