Event Plot

Server Request Timeline

Microservices request distribution over time

Output
Server Request Timeline
Python
import matplotlib.pyplot as plt
import numpy as np

# Simulate server requests
np.random.seed(42)
servers = ['API Gateway', 'Auth Service', 'Database', 'Cache', 'CDN']
request_times = [
    np.sort(np.random.exponential(0.5, 60).cumsum()),
    np.sort(np.random.exponential(0.8, 40).cumsum()),
    np.sort(np.random.exponential(0.3, 90).cumsum()),
    np.sort(np.random.exponential(0.2, 120).cumsum()),
    np.sort(np.random.exponential(0.4, 70).cumsum()),
]

# Status colors
colors = ['#10B981', '#3B82F6', '#F59E0B', '#22D3EE', '#8B5CF6']

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

for i, (times, color) in enumerate(zip(request_times, colors)):
    ax.eventplot(times, lineoffsets=i, linelengths=0.6, linewidths=1.2,
                 colors=color, alpha=0.8)
    
    # Request count badge
    ax.text(32, i, f'{len(times)} req', fontsize=9, va='center',
            color=color, fontweight='600')

# High load period
ax.axvspan(10, 15, color='#FEE2E2', alpha=0.5, zorder=0)
ax.text(12.5, 4.7, 'Peak Load', ha='center', fontsize=9, color='#DC2626')

# Styling
ax.set_yticks(range(len(servers)))
ax.set_yticklabels(servers, fontsize=11, fontweight='500')
ax.set_xlabel('Time (seconds)', fontsize=12, fontweight='500', color='#374151')
ax.set_xlim(0, 35)
ax.set_ylim(-0.5, len(servers) - 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')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support