Line & Scatter

Damped Oscillation

Damped oscillation with envelope and sample points.

Output
Damped Oscillation
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'wave': '#EC4899',       # Pink
    'envelope': '#64748B',   # Slate
    'samples': '#8B5CF6',    # Violet
    'background': '#FAFBFC',
    'text_muted': '#64748B',
    'grid': '#E2E8F0',
}

# === DATA ===
t = np.linspace(0, 10, 200)
decay = np.exp(-0.3 * t)
oscillation = decay * np.cos(2 * np.pi * 0.8 * t)
envelope_upper = decay
envelope_lower = -decay

t_samples = np.linspace(0, 10, 25)
decay_s = np.exp(-0.3 * t_samples)
samples = decay_s * np.cos(2 * np.pi * 0.8 * t_samples)

# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

# === PLOT ===
ax.plot(t, envelope_upper, '--', color=COLORS['envelope'], 
        linewidth=1.5, alpha=0.6, label='Envelope')
ax.plot(t, envelope_lower, '--', color=COLORS['envelope'], 
        linewidth=1.5, alpha=0.6)

ax.plot(t, oscillation, color=COLORS['wave'], linewidth=2,
        label='Signal', zorder=2)

ax.scatter(t_samples, samples, color=COLORS['samples'], s=35,
           edgecolors='white', linewidths=1.5,
           label='Samples', zorder=3)

# === AXES ===
ax.set_xlim(0, 10)
ax.set_ylim(-1.2, 1.2)
ax.set_xlabel('Time (s)', fontsize=10, color=COLORS['text_muted'], labelpad=10)
ax.set_ylabel('Amplitude', fontsize=10, color=COLORS['text_muted'], labelpad=10)

# Zero line
ax.axhline(y=0, color=COLORS['grid'], linewidth=1, zorder=1)

# === STYLING ===
for spine in ['top', 'right']:
    ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
    ax.spines[spine].set_color(COLORS['grid'])

ax.yaxis.grid(True, color=COLORS['grid'], linewidth=0.5, alpha=0.5)
ax.xaxis.grid(False)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)

ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
          ncol=3, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support