Area Chart

Cohort Retention Curves

User retention curves by cohort.

Output
Cohort Retention Curves
Python
import matplotlib.pyplot as plt
import numpy as np

# Data - User retention by cohort
weeks = np.arange(0, 13)
cohorts = {
    'Jan Cohort': [100, 65, 52, 45, 40, 36, 33, 31, 29, 28, 27, 26, 25],
    'Feb Cohort': [100, 70, 58, 50, 44, 40, 37, 35, 33, 31, 30, 29, 28],
    'Mar Cohort': [100, 75, 62, 55, 49, 45, 42, 40, 38, 36, 35, 34, 33],
}
colors = {'Jan Cohort': '#F5276C', 'Feb Cohort': '#27D3F5', 'Mar Cohort': '#6CF527'}

# Figure - LIGHT THEME
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

# Retention curves
for cohort, values in cohorts.items():
    ax.fill_between(weeks, 0, values, alpha=0.2, color=colors[cohort])
    ax.plot(weeks, values, color=colors[cohort], linewidth=2.5, label=cohort, marker='o', markersize=4)

# Styling
ax.set_xlabel('Week', color='#1f2937', fontsize=11)
ax.set_ylabel('Retention (%)', color='#1f2937', fontsize=11)
ax.set_title('User Retention by Monthly Cohort', color='#1f2937', fontsize=14, fontweight='bold', pad=15)
ax.tick_params(colors='#374151', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.yaxis.grid(True, color='#f3f4f6', linewidth=0.5)
ax.set_xlim(0, 12)
ax.set_ylim(0, 105)
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', labelcolor='#1f2937')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support