3D Fill Between

Parametric Spring

3D variable tension spring with orange and purple neon

Output
Parametric Spring
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')

# Variable spring parameters
n = 250
t = np.linspace(0, 10*np.pi, n)
r = 1 + 0.3*np.sin(t/2)  # Variable radius

x1 = r * np.cos(t)
y1 = r * np.sin(t)
z1 = np.linspace(0, 5, n)

x2 = r * 0.65 * np.cos(t)
y2 = r * 0.65 * np.sin(t)
z2 = z1

ax.plot(x1, y1, z1, linewidth=2.5, color='#F54927')
ax.plot(x2, y2, z2, linewidth=2.5, color='#4927F5')

# Spring coil fill
for i in range(0, n, 3):
    ax.plot([x1[i], x2[i]], [y1[i], y2[i]], [z1[i], z2[i]], 
            color='#27D3F5', alpha=0.35, linewidth=0.8)

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('Parametric Spring', 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=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