plot_customer_exposure#
- pymc_marketing.clv.plotting.plot_customer_exposure(df, linewidth=None, size=None, labels=None, colors=None, padding=0.25, ax=None)[source]#
Plot the recency and T of DataFrame of customers.
Plots customers as horizontal lines with markers representing their recency and T starting. Order is the same as the DataFrame and plotted from the bottom up.
The lines are colored by recency and T.
- Parameters:
- df
pd.DataFrame
A DataFrame with columns “recency” and “T” representing the recency and age of customers.
- linewidth
float
, optional The width of the horizontal lines in the plot.
- size
float
, optional The size of the markers in the plot.
- labels
Sequence
[str
], optional A sequence of labels for the legend. Default is [“Recency”, “T”].
- colors
Sequence
[str
], optional A sequence of colors for the legend. Default is [“C0”, “C1”].
- padding
float
, optional The padding around the plot. Default is 0.25.
- ax
plt.Axes
, optional A matplotlib axes instance to plot on. If None, a new figure and axes is created.
- df
- Returns:
plt.Axes
The matplotlib axes instance.
Examples
Plot customer exposure
df = pd.DataFrame({ "recency": [0, 1, 2, 3, 4], "T": [5, 5, 5, 5, 5] }) plot_customer_exposure(df)
Plot customer exposure ordered by recency and T
( df .sort_values(["recency", "T"]) .pipe(plot_customer_exposure) )
Plot exposure for only those with time until last purchase is less than 3
( df .query("T - recency < 3") .pipe(plot_customer_exposure) )