Cohort Plot
This module provides functionality for creating cohort plots from pandas DataFrames.
It is designed to visualize data distributions using color-coded heatmaps, helping to highlight trends and comparisons between different groups.
Core Features
- Color Mapping: Uses a predefined colormap for visualizing data.
- Customizable Labels: Supports custom labels for x-axis, y-axis, title, and colorbar.
- Source Text: Provides an option to add source attribution to the plot.
- Grid and Tick Customization: Applies standard styling for better readability.
Use Cases
- Cohort Analysis: Visualize how different groups behave over time.
- Category-Based Heatmaps: Compare values across different categories.
Limitations and Warnings
- Data Aggregation Required: The module does not perform data aggregation; data should be pre-aggregated before being passed to the function.
- Fixed Color Mapping: The module uses a predefined colormap without dynamic adjustments.
plot(df, cbar_label, x_label=None, y_label=None, title=None, ax=None, source_text=None, percentage=True, figsize=None, **kwargs)
Plots a cohort plot for the given DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Dataframe containing cohort analysis data. |
required |
cbar_label |
str
|
Label for the colorbar. |
required |
x_label |
str
|
Label for x-axis. |
None
|
y_label |
str
|
Label for y-axis. |
None
|
title |
str
|
Title of the plot. |
None
|
ax |
Axes
|
Matplotlib axes object to plot on. |
None
|
source_text |
str
|
Additional source text annotation. |
None
|
percentage |
bool
|
If True, displays cohort values as percentages. Defaults to False. |
True
|
figsize |
tuple[int, int]
|
The size of the plot. Defaults to None. |
None
|
**kwargs |
dict
|
Additional keyword arguments for cohort styling. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
SubplotBase |
SubplotBase
|
The matplotlib axes object. |