Raincloud Plot

Flight Delay by Airline

Departure delay distribution across carriers

Output
Flight Delay by Airline
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(211)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#276CF5', '#F54927', '#6CF527', '#F5B027']

airlines = ['Delta', 'United', 'Southwest', 'American']
data = pd.DataFrame({
    'Delay': np.concatenate([
        np.random.exponential(12, 100),
        np.random.exponential(18, 95),
        np.random.exponential(10, 110),
        np.random.exponential(15, 90)
    ]),
    'Airline': ['Delta']*100 + ['United']*95 + ['Southwest']*110 + ['American']*90
})

fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

pt.RainCloud(x='Airline', y='Delay', data=data, palette=COLORS,
             bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
             dodge=True, pointplot=False, move=.2)

ax.axvline(15, color='#ef4444', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(16, 3.5, 'On-Time Threshold', color='#ef4444', fontsize=9)

ax.set_xlabel('Delay (minutes)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Airline', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Flight Delays by Airline', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support