Event Plot

Social Media Engagement

Cross-platform engagement events over time

Output
Social Media Engagement
Python
import matplotlib.pyplot as plt
import numpy as np

# Simulate social media events
np.random.seed(42)
platforms = ['Twitter/X', 'Instagram', 'TikTok', 'LinkedIn', 'YouTube']
engagement = [
    np.sort(np.random.exponential(0.5, 120).cumsum()),
    np.sort(np.random.exponential(0.3, 180).cumsum()),
    np.sort(np.random.exponential(0.2, 250).cumsum()),
    np.sort(np.random.exponential(1.0, 50).cumsum()),
    np.sort(np.random.exponential(0.8, 70).cumsum()),
]

# Platform brand colors
colors = ['#1DA1F2', '#E4405F', '#000000', '#0A66C2', '#FF0000']

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

for i, (events, color) in enumerate(zip(engagement, colors)):
    visible = events[events <= 48]
    ax.eventplot(visible, lineoffsets=i, linelengths=0.5, linewidths=1.5,
                 colors=color, alpha=0.75)
    
    # Engagement rate
    rate = len(visible)
    ax.text(49.5, i, f'{rate}', fontsize=11, va='center',
            color=color, fontweight='bold')

# Viral moment highlight
ax.axvspan(20, 28, color='#FEF3C7', alpha=0.5, zorder=0)
ax.text(24, 4.7, 'Viral Post', ha='center', fontsize=10, 
        color='#D97706', fontweight='600')

# Time markers
ax.set_xticks(range(0, 49, 6))
ax.set_xticklabels([f'{h}h' for h in range(0, 49, 6)], fontsize=9)

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