3D Line

DNA Double Helix Structure

A 3D visualization of DNA double helix structure with two intertwined strands in cyan and magenta, connected by base pairs.

Output
DNA Double Helix Structure
Python
import matplotlib.pyplot as plt
import numpy as np

# DNA Double Helix
n = 200
t = np.linspace(0, 4 * np.pi, n)

# First strand
x1 = np.cos(t)
y1 = np.sin(t)
z1 = t / (4 * np.pi)

# Second strand (180° offset)
x2 = np.cos(t + np.pi)
y2 = np.sin(t + np.pi)
z2 = t / (4 * np.pi)

fig = plt.figure(figsize=(10, 8), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d', facecolor='#0a0a0f')

# Plot both strands with glow effect
ax.plot(x1, y1, z1, color='#06b6d4', linewidth=3, alpha=0.3)
ax.plot(x1, y1, z1, color='#22d3ee', linewidth=1.5)
ax.plot(x2, y2, z2, color='#ec4899', linewidth=3, alpha=0.3)
ax.plot(x2, y2, z2, color='#f472b6', linewidth=1.5)

# Base pair connections
for i in range(0, n, 10):
    ax.plot([x1[i], x2[i]], [y1[i], y2[i]], [z1[i], z2[i]], 
            color='#334155', linewidth=0.8, alpha=0.6)

ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.set_zlim(0, 1)

# Style
ax.set_xlabel('X', color='white', fontsize=10)
ax.set_ylabel('Y', color='white', fontsize=10)
ax.set_zlabel('Z', color='white', fontsize=10)
ax.set_title('DNA Double Helix Structure', color='white', fontsize=14, fontweight='bold', pad=20)

ax.tick_params(colors='#64748b', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#1e293b')
ax.yaxis.pane.set_edgecolor('#1e293b')
ax.zaxis.pane.set_edgecolor('#1e293b')
ax.grid(True, alpha=0.2, color='#334155')

ax.view_init(elev=20, azim=45)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support