3D Stem

ECG R-Peak Detection

Cardiology visualization showing detected heartbeat R-peaks across multiple ECG leads.

Output
ECG R-Peak Detection
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(777)

# ECG R-peak events
n_beats = 20
beat_times = np.cumsum(np.random.uniform(0.7, 1.0, n_beats))  # ~60-85 BPM
r_amplitude = np.random.uniform(0.8, 1.2, n_beats)
lead = np.random.choice([0, 0.5, 1], n_beats)  # Different ECG leads

x = beat_times / beat_times.max()
y = lead
z = r_amplitude

fig = plt.figure(figsize=(10, 8), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d', facecolor='#0a0a0f')

markerline, stemlines, baseline = ax.stem(x, y, z, linefmt='-', markerfmt='o', basefmt=' ')
plt.setp(stemlines, color='#ef4444', linewidth=2, alpha=0.8)
plt.setp(markerline, color='#f87171', markersize=9)

ax.set_xlabel('Time (normalized)', color='white', fontsize=10)
ax.set_ylabel('ECG Lead', color='white', fontsize=10)
ax.set_zlabel('R-Peak Amplitude', color='white', fontsize=10)
ax.set_title('ECG R-Peak Detection', 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.view_init(elev=20, azim=35)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support