Ridgeline Plot

Flight Delays by Airline

Departure delay distributions across major airlines

Output
Flight Delays by Airline
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(42)

airlines = ['Delta', 'United', 'American', 'Southwest', 'JetBlue']
colors = ['#27D3F5', '#F5276C', '#6CF527', '#F5B027', '#4927F5']

# Generate delay data in minutes
data = {
    'Delta': np.concatenate([np.random.exponential(12, 200), np.random.normal(5, 3, 100)]),
    'United': np.concatenate([np.random.exponential(18, 200), np.random.normal(8, 4, 100)]),
    'American': np.concatenate([np.random.exponential(15, 200), np.random.normal(6, 3, 100)]),
    'Southwest': np.concatenate([np.random.exponential(10, 200), np.random.normal(4, 2, 100)]),
    'JetBlue': np.concatenate([np.random.exponential(14, 200), np.random.normal(7, 3, 100)])
}

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

overlap = 2.2
x_range = np.linspace(-10, 80, 300)

for i, (airline, delays) in enumerate(data.items()):
    delays = np.clip(delays, 0, 80)
    kde = stats.gaussian_kde(delays, bw_method=0.25)
    y = kde(x_range) * 8
    baseline = i * overlap
    
    ax.fill_between(x_range, baseline, y + baseline, 
                    alpha=0.75, color=colors[i], linewidth=0)
    ax.plot(x_range, y + baseline, color=colors[i], linewidth=2)
    ax.text(-12, baseline + 0.3, airline, fontsize=11, color='#1f2937',
            ha='right', va='bottom', fontweight='500')

ax.set_xlim(-35, 80)
ax.set_ylim(-0.5, len(airlines) * overlap + 1.5)
ax.set_xlabel('Delay (minutes)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Flight Delays by Airline', 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['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_color('#e5e7eb')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support