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:
dfpd.DataFrame

A DataFrame with columns “recency” and “T” representing the recency and age of customers.

linewidthfloat, optional

The width of the horizontal lines in the plot.

sizefloat, optional

The size of the markers in the plot.

labelsSequence[str], optional

A sequence of labels for the legend. Default is [“Recency”, “T”].

colorsSequence[str], optional

A sequence of colors for the legend. Default is [“C0”, “C1”].

paddingfloat, optional

The padding around the plot. Default is 0.25.

axplt.Axes, optional

A matplotlib axes instance to plot on. If None, a new figure and axes is created.

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)
)