3D Line
Trefoil Knot - Mathematical Curve
The famous trefoil knot, a closed mathematical curve that cannot be untangled without cutting, rendered with the neon color palette.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Trefoil knot - a famous mathematical curve
n = 500
t = np.linspace(0, 2 * np.pi, n)
# Trefoil knot parametric equations
x = np.sin(t) + 2 * np.sin(2 * t)
y = np.cos(t) - 2 * np.cos(2 * t)
z = -np.sin(3 * t)
fig = plt.figure(figsize=(10, 8), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d', facecolor='#0a0a0f')
# Create color array based on position
colors_val = np.linspace(0, 1, n)
# Draw segments with rainbow-like neon colors
neon_colors = ['#F5276C', '#F54927', '#F5B027', '#6CF527', '#27F5B0', '#27D3F5', '#276CF5', '#4927F5']
for i in range(n-1):
color_idx = int(colors_val[i] * (len(neon_colors) - 1))
ax.plot(x[i:i+2], y[i:i+2], z[i:i+2],
color=neon_colors[color_idx], linewidth=2.5)
# Glow effect
ax.plot(x, y, z, color='#ec4899', linewidth=6, alpha=0.15)
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('Trefoil Knot - Mathematical Curve', 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=60)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
3D Charts
More 3D Line examples
☕