Ridgeline Plot

Social Engagement by Platform

User engagement distributions across social media platforms

Output
Social Engagement by Platform
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(42)

# Reverse order so Facebook is at top (drawn last, most visible)
platforms = ['Facebook', 'LinkedIn', 'Twitter', 'Instagram', 'TikTok']
colors = ['#4927F5', '#276CF5', '#27D3F5', '#F5B027', '#F5276C']

# Generate engagement rate data (percentage)
data = {
    'Facebook': np.random.beta(1.5, 35, 400) * 10 + 0.2,
    'LinkedIn': np.random.beta(1.8, 30, 400) * 12 + 0.3,
    'Twitter': np.random.beta(2, 25, 400) * 15 + 0.5,
    'Instagram': np.random.beta(2.5, 20, 400) * 20 + 1,
    'TikTok': np.random.beta(3, 15, 400) * 25 + 2
}

fig, ax = plt.subplots(figsize=(12, 8), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

overlap = 1.6
x_range = np.linspace(0, 15, 300)

for i, (platform, engagement) in enumerate(data.items()):
    kde = stats.gaussian_kde(engagement, bw_method=0.35)
    y = kde(x_range) * 3.5
    baseline = i * overlap
    
    ax.fill_between(x_range, baseline, y + baseline, 
                    alpha=0.7, color=colors[i], linewidth=0)
    ax.plot(x_range, y + baseline, color=colors[i], linewidth=2)
    ax.text(-0.3, baseline + 0.15, platform, fontsize=11, color='white',
            ha='right', va='bottom', fontweight='500')

ax.set_xlim(-3.5, 15)
ax.set_ylim(-0.3, len(platforms) * overlap + 2.5)
ax.set_xlabel('Engagement Rate (%)', fontsize=12, color='white', fontweight='500')
ax.set_title('Social Engagement by Platform', fontsize=16, color='white', 
             fontweight='bold', pad=20)

ax.tick_params(axis='x', colors='#888888', labelsize=10)
ax.tick_params(axis='y', left=False, labelleft=False)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support