3D Line
Torus Knot (5,2)
A (5,2) torus knot - a curve that winds 5 times around a torus while going through the hole 2 times, in magenta.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Torus knot (5,2)
n = 1000
t = np.linspace(0, 2 * np.pi, n)
p, q = 5, 2 # Torus knot parameters
r = np.cos(q * t) + 2
x = r * np.cos(p * t)
y = r * np.sin(p * t)
z = -np.sin(q * t)
fig = plt.figure(figsize=(10, 8), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d', facecolor='#0a0a0f')
# Glow effect with magenta
ax.plot(x, y, z, color='#ec4899', linewidth=5, alpha=0.15)
ax.plot(x, y, z, color='#f472b6', linewidth=2.5)
ax.plot(x, y, z, color='#fbcfe8', linewidth=0.8)
ax.set_xlim(-4, 4)
ax.set_ylim(-4, 4)
ax.set_zlim(-2, 2)
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('Torus Knot (5,2)', 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=30, azim=45)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
3D Charts
More 3D Line examples
☕