Area Chart

Empirical CDF Comparison

Cumulative distribution comparison - R ecdf style

Output
Empirical CDF Comparison
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)
group_a = np.random.normal(50, 10, 200)
group_b = np.random.normal(55, 12, 200)

def ecdf(data):
    x = np.sort(data)
    y = np.arange(1, len(data) + 1) / len(data)
    return x, y

x_a, y_a = ecdf(group_a)
x_b, y_b = ecdf(group_b)

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

ax.fill_between(x_a, 0, y_a, alpha=0.4, color='#27D3F5', step='post')
ax.fill_between(x_b, 0, y_b, alpha=0.4, color='#F5276C', step='post')
ax.step(x_a, y_a, color='#27D3F5', linewidth=2, where='post', label=f'Group A (μ={np.mean(group_a):.1f})')
ax.step(x_b, y_b, color='#F5276C', linewidth=2, where='post', label=f'Group B (μ={np.mean(group_b):.1f})')

# KS statistic visualization
from scipy import stats
ks_stat, p_val = stats.ks_2samp(group_a, group_b)
ax.text(0.95, 0.15, f'KS stat: {ks_stat:.3f}\np-value: {p_val:.4f}', transform=ax.transAxes,
        color='white', fontsize=10, ha='right', va='bottom', 
        bbox=dict(boxstyle='round', facecolor='#1a1a2e', edgecolor='#333333'))

ax.set_xlabel('Value', color='white', fontsize=11, fontweight='500')
ax.set_ylabel('Cumulative Probability', color='white', fontsize=11, fontweight='500')
ax.set_title('Empirical Cumulative Distribution Function', color='white', fontsize=13, fontweight='600', pad=15)
ax.tick_params(colors='#888888', labelsize=9)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#333333')
ax.spines['bottom'].set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.legend(facecolor='#0a0a0f', edgecolor='#333333', labelcolor='white')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support