Mirror Chart

Domestic vs International Flight Delays

Mirror histogram comparing flight punctuality with compensation analysis

Output
Domestic vs International Flight Delays
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde

np.random.seed(1985)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'

domestic = np.random.exponential(15, 1000)
intl = np.random.exponential(25, 600) + 10
domestic = domestic[domestic < 90]
intl = intl[(intl > 5) & (intl < 120)]

fig, ax = plt.subplots(figsize=(12, 7), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

x = np.linspace(0, 120, 400)

kde_d = gaussian_kde(domestic)
y_d = kde_d(x)
ax.fill_between(x, y_d, alpha=0.3, color='#27D3F5')
ax.plot(x, y_d, color='#27D3F5', linewidth=4, alpha=0.3)
ax.plot(x, y_d, color='#27D3F5', linewidth=2, label='Domestic Flights')

kde_i = gaussian_kde(intl)
y_i = kde_i(x) * -1
ax.fill_between(x, y_i, alpha=0.3, color='#F54927')
ax.plot(x, y_i, color='#F54927', linewidth=4, alpha=0.3)
ax.plot(x, y_i, color='#F54927', linewidth=2, label='International Flights')

ax.axhline(0, color='#333', linewidth=1.5)

med_d = np.median(domestic)
med_i = np.median(intl)
ax.axvline(med_d, color='#27D3F5', linestyle='--', linewidth=1.5, alpha=0.7)
ax.axvline(med_i, color='#F54927', linestyle='--', linewidth=1.5, alpha=0.7)

on_time_d = (domestic < 15).sum() / len(domestic) * 100
on_time_i = (intl < 15).sum() / len(intl) * 100

stats_text = 'On-Time (< 15 min):\nDomestic: %.0f%%\nInternational: %.0f%%' % (on_time_d, on_time_i)
ax.text(0.02, 0.98, stats_text.replace('\n', chr(10)), transform=ax.transAxes, fontsize=10,
        color=TEXT_COLOR, verticalalignment='top', fontfamily='monospace',
        bbox=dict(boxstyle='round,pad=0.5', facecolor='#1a1a2e', edgecolor='#333', alpha=0.9))

delay_diff = med_i - med_d
ax.text(0.98, 0.98, 'Intl avg +%.0f min delay' % delay_diff, 
        transform=ax.transAxes, fontsize=11, color='#F54927', ha='right', va='top', fontweight='bold')

ax.set_xlabel('Delay Time (minutes)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Flight Delays: Domestic vs International', fontsize=14, 
             color=TEXT_COLOR, fontweight='bold', pad=15)

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

ax.legend(loc='upper right', facecolor='#1a1a2e', edgecolor='#333', 
          labelcolor=TEXT_COLOR, fontsize=10)
ax.set_xlim(0, 120)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support