Ridgeline Plot

Delivery Time by Carrier

Shipping speed distributions with modern gradient aesthetics

Output
Delivery Time by Carrier
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(654)

carriers = ['FedEx', 'UPS', 'USPS', 'DHL', 'Amazon', 'OnTrac']
colors = ['#F54927', '#4927F5', '#276CF5', '#F5D327', '#F5B027', '#6CF527']

data = {
    'FedEx': np.random.gamma(2, 0.8, 500),
    'UPS': np.random.gamma(2.2, 0.9, 500),
    'USPS': np.random.gamma(3, 1.2, 500),
    'DHL': np.random.gamma(2.5, 1, 500),
    'Amazon': np.random.gamma(1.5, 0.7, 500),
    'OnTrac': np.random.gamma(2.8, 1.1, 500)
}

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

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

for i, (carrier, days) in enumerate(data.items()):
    kde = stats.gaussian_kde(days, bw_method=0.3)
    y = kde(x_range) * 3.5
    baseline = i * overlap
    
    ax.fill_between(x_range, baseline, y + baseline, alpha=0.7, color=colors[i])
    ax.plot(x_range, y + baseline, color=colors[i], linewidth=2.5)
    
    ax.text(-0.3, baseline + 0.12, carrier, fontsize=11, color='#1f2937',
            ha='right', va='bottom', fontweight='600')

ax.set_xlim(-2, 10)
ax.set_ylim(-0.3, len(carriers) * overlap + 1.8)
ax.set_xlabel('Days to Delivery', fontsize=12, color='#374151', fontweight='500')
ax.set_title('Delivery Time by Carrier', fontsize=16, color='#1f2937', fontweight='bold', pad=20)

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

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support