KDE Plot

Exam Completion Time Distribution

KDE showing time taken to complete standardized exams.

Output
Exam Completion Time Distribution
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(108)

times = np.random.normal(75, 20, 1000)
times = times[(times > 20) & (times < 120)]

kde = stats.gaussian_kde(times)
x = np.linspace(20, 120, 500)
y = kde(x)

fig, ax = plt.subplots(figsize=(12, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

ax.fill_between(x, y, alpha=0.4, color='#F527B0')
ax.plot(x, y, color='#F527B0', linewidth=3)

p25 = np.percentile(times, 25)
p75 = np.percentile(times, 75)
ax.axvspan(p25, p75, alpha=0.15, color='#27D3F5', label='Interquartile Range')
ax.axvline(90, color='#F5276C', linestyle='--', linewidth=2, label='Time Limit')

median = np.median(times)
ax.axvline(median, color='#374151', linestyle='-', linewidth=2)
ax.text(median+2, max(y)*0.9, 'Median: ' + str(int(median)) + ' min', color='#374151', fontsize=10, fontweight='bold')

ax.set_xlabel('Time (minutes)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Exam Completion Time Distribution', fontsize=16, color='#1f2937', fontweight='bold', pad=15)

ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
    spine.set_color('#d1d5db')
ax.legend(loc='upper right', facecolor='#f9fafb', edgecolor='#d1d5db', labelcolor='#374151')
ax.grid(True, alpha=0.3, color='#e5e7eb')
ax.set_xlim(20, 120)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support