3D Fill Between

Trefoil Knot

3D trefoil knot with deep purple and coral neon

Output
Trefoil Knot
Python
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(10, 8), facecolor='white')
ax = fig.add_subplot(111, projection='3d')
ax.set_facecolor('white')

# Trefoil knot parametric equations
n = 250
t = np.linspace(0, 2*np.pi, n)

x = np.sin(t) + 2*np.sin(2*t)
y = np.cos(t) - 2*np.cos(2*t)
z = -np.sin(3*t)

# Create ribbon with offset
offset = 0.18
x2 = x + offset * np.cos(3*t)
y2 = y + offset * np.sin(3*t)
z2 = z + offset * 0.5

ax.plot(x, y, z, linewidth=3, color='#5314E6')
ax.plot(x2, y2, z2, linewidth=3, color='#F5276C')

# Ribbon surface
for i in range(0, n, 4):
    ax.plot([x[i], x2[i]], [y[i], y2[i]], [z[i], z2[i]], 
            color='#D3F527', alpha=0.35, linewidth=0.7)

ax.set_xlabel('X', fontsize=11, color='#1f2937')
ax.set_ylabel('Y', fontsize=11, color='#1f2937')
ax.set_zlabel('Z', fontsize=11, color='#1f2937')
ax.set_title('Trefoil Knot', fontsize=14, color='#1f2937', fontweight='bold', pad=15)

ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#000000')
ax.yaxis.pane.set_edgecolor('#000000')
ax.zaxis.pane.set_edgecolor('#000000')
ax.tick_params(colors='#000000', labelsize=9)
ax.grid(True, alpha=0.5, linewidth=0.5)
ax.xaxis._axinfo['grid']['color'] = '#000000'
ax.yaxis._axinfo['grid']['color'] = '#000000'
ax.zaxis._axinfo['grid']['color'] = '#000000'

ax.view_init(elev=30, azim=60)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support