3D Line
Damped 3D Harmonic Oscillator
A damped 3D harmonic oscillator showing energy decay over time with different x and y frequencies.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# 3D Damped harmonic oscillator trajectory
n = 500
t = np.linspace(0, 10, n)
# Damped oscillation
damping = 0.15
omega_x, omega_y = 3, 4
x = np.exp(-damping * t) * np.cos(omega_x * t)
y = np.exp(-damping * t) * np.sin(omega_y * t)
z = t
fig = plt.figure(figsize=(10, 8), facecolor='#ffffff')
ax = fig.add_subplot(111, projection='3d', facecolor='#ffffff')
# Teal/cyan on light background
ax.plot(x, y, z, color='#0891b2', linewidth=2.5, alpha=0.4)
ax.plot(x, y, z, color='#06b6d4', linewidth=1.5)
# Mark start and end points
ax.scatter([x[0]], [y[0]], [z[0]], color='#22c55e', s=80, label='Start', zorder=5)
ax.scatter([x[-1]], [y[-1]], [z[-1]], color='#ef4444', s=80, label='End', zorder=5)
ax.set_xlim(-1.2, 1.2)
ax.set_ylim(-1.2, 1.2)
ax.set_zlim(0, 10)
ax.set_xlabel('X', color='#1f2937', fontsize=10)
ax.set_ylabel('Y', color='#1f2937', fontsize=10)
ax.set_zlabel('Time', color='#1f2937', fontsize=10)
ax.set_title('Damped 3D Harmonic Oscillator', color='#1f2937', fontsize=14, fontweight='bold', pad=20)
ax.tick_params(colors='#6b7280', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#e5e7eb')
ax.yaxis.pane.set_edgecolor('#e5e7eb')
ax.zaxis.pane.set_edgecolor('#e5e7eb')
ax.grid(True, alpha=0.3, color='#d1d5db')
ax.legend(loc='upper right', fontsize=9)
ax.view_init(elev=20, azim=35)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
3D Charts
More 3D Line examples
☕