Cohort Plot Gallery¶
The cohort plot is used for visualizing cohort analysis data as a color-coded heatmap. It's ideal for showing how groups of customers behave over time, retention rates, and comparing performance across different cohorts.
Cohort plots excel at:
- Customer Retention Analysis: Track how customer cohorts perform over time
- Behavioral Analysis: Compare different groups' behavior patterns
- Performance Tracking: Monitor cohort performance across periods
- Trend Identification: Identify patterns and trends in retention or engagement
In [ ]:
Copied!
import matplotlib.pyplot as plt
import pandas as pd
from pyretailscience.plots import cohort
import matplotlib.pyplot as plt
import pandas as pd
from pyretailscience.plots import cohort
Basic Cohort Plot¶
Visualize customer retention rates across different cohorts and time periods. By default, values are displayed as percentages.
In [ ]:
Copied!
# Create sample customer retention data
# fmt: off
retention_data = pd.DataFrame(
{
"Month 1": [1.00, 1.00, 1.00, 1.00, 1.00],
"Month 2": [0.68, 0.72, 0.75, 0.71, 0.69],
"Month 3": [0.52, 0.58, 0.61, 0.56, 0.53],
"Month 4": [0.41, 0.47, 0.52, 0.48, 0.44],
"Month 5": [0.34, 0.40, 0.46, 0.42, 0.38],
"Month 6": [0.29, 0.35, 0.41, 0.37, 0.33],
},
index=["Jan 2024", "Feb 2024", "Mar 2024", "Apr 2024", "May 2024"],
)
# fmt: on
ax = cohort.plot(
retention_data,
cbar_label="Retention Rate",
x_label="Months Since First Purchase",
y_label="Cohort (First Purchase Month)",
title="Customer Retention Cohort Analysis",
figsize=(10, 6),
)
plt.show()
# Create sample customer retention data
# fmt: off
retention_data = pd.DataFrame(
{
"Month 1": [1.00, 1.00, 1.00, 1.00, 1.00],
"Month 2": [0.68, 0.72, 0.75, 0.71, 0.69],
"Month 3": [0.52, 0.58, 0.61, 0.56, 0.53],
"Month 4": [0.41, 0.47, 0.52, 0.48, 0.44],
"Month 5": [0.34, 0.40, 0.46, 0.42, 0.38],
"Month 6": [0.29, 0.35, 0.41, 0.37, 0.33],
},
index=["Jan 2024", "Feb 2024", "Mar 2024", "Apr 2024", "May 2024"],
)
# fmt: on
ax = cohort.plot(
retention_data,
cbar_label="Retention Rate",
x_label="Months Since First Purchase",
y_label="Cohort (First Purchase Month)",
title="Customer Retention Cohort Analysis",
figsize=(10, 6),
)
plt.show()
Revenue Cohort Analysis¶
Track revenue contribution of different cohorts over time using percentage=False to display raw values instead of percentages.
In [ ]:
Copied!
# Create sample revenue cohort data (in thousands)
# fmt: off
revenue_data = pd.DataFrame(
{
"Month 1": [145, 167, 189, 156, 172],
"Month 2": [98, 115, 134, 108, 121],
"Month 3": [76, 92, 112, 85, 97],
"Month 4": [59, 75, 94, 68, 78],
"Month 5": [48, 63, 81, 56, 65],
"Month 6": [41, 55, 72, 48, 56],
},
index=["Q1 2024", "Q2 2024", "Q3 2024", "Q4 2024", "Q1 2025"],
)
# fmt: on
ax = cohort.plot(
revenue_data,
cbar_label="Revenue ($000s)",
x_label="Months Since Acquisition",
y_label="Acquisition Cohort",
title="Revenue Contribution by Customer Cohort",
percentage=False,
figsize=(10, 6),
)
plt.show()
# Create sample revenue cohort data (in thousands)
# fmt: off
revenue_data = pd.DataFrame(
{
"Month 1": [145, 167, 189, 156, 172],
"Month 2": [98, 115, 134, 108, 121],
"Month 3": [76, 92, 112, 85, 97],
"Month 4": [59, 75, 94, 68, 78],
"Month 5": [48, 63, 81, 56, 65],
"Month 6": [41, 55, 72, 48, 56],
},
index=["Q1 2024", "Q2 2024", "Q3 2024", "Q4 2024", "Q1 2025"],
)
# fmt: on
ax = cohort.plot(
revenue_data,
cbar_label="Revenue ($000s)",
x_label="Months Since Acquisition",
y_label="Acquisition Cohort",
title="Revenue Contribution by Customer Cohort",
percentage=False,
figsize=(10, 6),
)
plt.show()