Mirror Chart

Express vs Standard Shipping

Mirror histogram comparing delivery times with SLA compliance

Output
Express vs Standard Shipping
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde

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

express = np.random.gamma(2, 0.5, 800) + 1
standard = np.random.gamma(3, 1.5, 1000) + 3
express = express[express < 6]
standard = standard[(standard > 2) & (standard < 15)]

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

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

kde_e = gaussian_kde(express)
y_e = kde_e(x)
ax.fill_between(x, y_e, alpha=0.3, color='#6CF527')
ax.plot(x, y_e, color='#6CF527', linewidth=4, alpha=0.3)
ax.plot(x, y_e, color='#6CF527', linewidth=2, label='Express Shipping')

kde_s = gaussian_kde(standard)
y_s = kde_s(x) * -1
ax.fill_between(x, y_s, alpha=0.3, color='#F5276C')
ax.plot(x, y_s, color='#F5276C', linewidth=4, alpha=0.3)
ax.plot(x, y_s, color='#F5276C', linewidth=2, label='Standard Shipping')

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

med_e = np.median(express)
med_s = np.median(standard)
ax.axvline(med_e, color='#6CF527', linestyle='--', linewidth=1.5, alpha=0.7)
ax.axvline(med_s, color='#F5276C', linestyle='--', linewidth=1.5, alpha=0.7)

time_saved = med_s - med_e
pct_faster = (time_saved / med_s) * 100

stats_text = 'Delivery Time:\nExpress: %.1f days median\nStandard: %.1f days median\nTime saved: %.1f days' % (med_e, med_s, time_saved)
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))

ax.text(0.98, 0.98, 'Express is %.0f%% faster' % pct_faster, 
        transform=ax.transAxes, fontsize=11, color='#6CF527', ha='right', va='top', fontweight='bold')

ax.set_xlabel('Delivery Time (days)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('E-Commerce Delivery: Express vs Standard', 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, 15)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support