Event Plot

Neural Spike Train

Visualize neuronal firing patterns across multiple channels

Output
Neural Spike Train
Python
import matplotlib.pyplot as plt
import numpy as np

# Simulate neural spike trains
np.random.seed(42)
neurons = ['Neuron 1', 'Neuron 2', 'Neuron 3', 'Neuron 4', 'Neuron 5']
spike_trains = [np.sort(np.random.exponential(0.1, np.random.randint(30, 80)).cumsum()) 
                for _ in neurons]

# Colors for each neuron
colors = ['#6366F1', '#8B5CF6', '#A855F7', '#D946EF', '#EC4899']

# Create figure
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#0F172A')
ax.set_facecolor('#0F172A')

# Event plot with glow effect
for i, (spikes, color) in enumerate(zip(spike_trains, colors)):
    # Glow layer
    ax.eventplot(spikes, lineoffsets=i, linelengths=0.7, linewidths=3,
                 colors=color, alpha=0.3)
    # Main layer
    ax.eventplot(spikes, lineoffsets=i, linelengths=0.6, linewidths=1.5,
                 colors=color, alpha=0.9)

# Stimulus marker
ax.axvline(2.0, color='#FBBF24', linewidth=2, linestyle='--', alpha=0.7)
ax.text(2.05, 4.7, 'Stimulus', fontsize=10, color='#FBBF24', fontweight='500')

# Styling
ax.set_yticks(range(len(neurons)))
ax.set_yticklabels(neurons, fontsize=10, color='white')
ax.set_xlabel('Time (s)', fontsize=12, fontweight='500', color='#94A3B8')
ax.set_xlim(0, 8)
ax.set_ylim(-0.5, len(neurons) - 0.5)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#334155')
ax.spines['bottom'].set_color('#334155')
ax.tick_params(colors='#94A3B8', labelsize=10)
ax.xaxis.grid(True, linestyle='--', alpha=0.2, color='#475569')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support