Event Plot
User Activity Timeline
Daily user engagement patterns with peak hour analysis
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Simulate user sessions
np.random.seed(42)
users = ['User A', 'User B', 'User C', 'User D', 'User E', 'User F']
activities = [
np.sort(np.random.uniform(8, 22, np.random.randint(15, 40))),
np.sort(np.random.uniform(6, 23, np.random.randint(20, 50))),
np.sort(np.random.uniform(9, 18, np.random.randint(10, 25))),
np.sort(np.random.uniform(7, 21, np.random.randint(25, 45))),
np.sort(np.random.uniform(10, 20, np.random.randint(8, 20))),
np.sort(np.random.uniform(0, 24, np.random.randint(30, 60))),
]
# Activity level colors
colors = ['#3B82F6', '#8B5CF6', '#06B6D4', '#10B981', '#F59E0B', '#EF4444']
# Create figure
fig, ax = plt.subplots(figsize=(12, 6), facecolor='white')
for i, (times, color) in enumerate(zip(activities, colors)):
ax.eventplot(times, lineoffsets=i, linelengths=0.5, linewidths=2,
colors=color, alpha=0.75)
# Session count
ax.text(24.5, i, f'{len(times)}', fontsize=10, va='center',
color=color, fontweight='bold')
# Peak hours highlight
ax.axvspan(9, 12, color='#FEF3C7', alpha=0.5, zorder=0)
ax.axvspan(14, 17, color='#FEF3C7', alpha=0.5, zorder=0)
ax.text(10.5, 5.7, 'Peak', ha='center', fontsize=9, color='#D97706')
ax.text(15.5, 5.7, 'Peak', ha='center', fontsize=9, color='#D97706')
# Hour markers
ax.set_xticks(range(0, 25, 3))
ax.set_xticklabels([f'{h:02d}:00' for h in range(0, 25, 3)], fontsize=9)
# Styling
ax.set_yticks(range(len(users)))
ax.set_yticklabels(users, fontsize=11, fontweight='500')
ax.set_xlabel('Time of Day', fontsize=12, fontweight='500', color='#374151')
ax.set_xlim(0, 26)
ax.set_ylim(-0.5, len(users) - 0.5)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#E5E7EB')
ax.spines['bottom'].set_color('#E5E7EB')
ax.tick_params(colors='#6B7280', labelsize=10)
ax.xaxis.grid(True, linestyle='--', alpha=0.3, color='#D1D5DB')
# Sessions label
ax.text(25.5, 5.5, 'Sessions', fontsize=9, color='#6B7280', rotation=90, va='top')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Event Plot examples
☕