ECDF Plot
Age Demographics ECDF
Light theme ECDF showing population age distribution
Output
Python
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
np.random.seed(42)
ages = np.clip(np.random.gamma(5, 8, 1000), 0, 100)
ax.ecdf(ages, color='#0ea5e9', linewidth=2.5)
median_age = np.median(ages)
ax.axvline(x=median_age, color='#f97316', linestyle='--', linewidth=2, label=f'Median: {median_age:.0f} years')
ax.axvline(x=18, color='#22c55e', linestyle=':', linewidth=2, alpha=0.7, label='Adult (18+)')
ax.axvline(x=65, color='#ef4444', linestyle=':', linewidth=2, alpha=0.7, label='Senior (65+)')
ax.set_xlabel('Age (years)', fontsize=12, color='#1f2937')
ax.set_ylabel('Cumulative Probability', fontsize=12, color='#1f2937')
ax.set_title('Population Age Distribution', fontsize=16, fontweight='bold', color='#1f2937', pad=20)
ax.legend(loc='lower right')
ax.grid(True, alpha=0.3)
for spine in ['top', 'right']:
ax.spines[spine].set_visible(False)
plt.tight_layout()
Library
Matplotlib
Category
Statistical
More ECDF Plot examples
☕