ECDF Plot

Sleep Duration ECDF

Light theme ECDF showing nightly sleep patterns

Output
Sleep Duration ECDF
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)
sleep_hours = np.clip(np.random.normal(7, 1.2, 500), 3, 12)

ax.ecdf(sleep_hours, color='#6366f1', linewidth=2.5)

recommended_min = 7
recommended_max = 9
ax.axvline(x=recommended_min, color='#22c55e', linestyle='--', linewidth=2, label='Recommended range')
ax.axvline(x=recommended_max, color='#22c55e', linestyle='--', linewidth=2)
ax.axvspan(recommended_min, recommended_max, alpha=0.1, color='#22c55e')

ax.set_xlabel('Sleep Duration (hours)', fontsize=12, color='#1f2937')
ax.set_ylabel('Cumulative Probability', fontsize=12, color='#1f2937')
ax.set_title('Nightly Sleep Duration ECDF', 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

Did this help you?

Support PyLucid to keep it free & growing

Support