KDE Plot
Mobile App Session Duration
KDE of user session lengths in mobile applications.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(110)
sessions = np.random.lognormal(2.5, 0.8, 2000)
sessions = sessions[sessions < 60]
kde = stats.gaussian_kde(sessions)
x = np.linspace(0, 60, 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='#D3F527')
ax.plot(x, y, color='#D3F527', linewidth=3)
p50 = np.percentile(sessions, 50)
p90 = np.percentile(sessions, 90)
ax.axvline(p50, color='#27D3F5', linestyle='--', linewidth=2, label='Median: ' + str(round(p50, 1)) + ' min')
ax.axvline(p90, color='#F5276C', linestyle='--', linewidth=2, label='P90: ' + str(round(p90, 1)) + ' min')
ax.axvspan(5, 15, alpha=0.1, color='#6CF527', label='Engaged Users')
ax.set_xlabel('Session Duration (minutes)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Mobile App Session Duration', 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(0, 60)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕