"""
Sankey diagram of web-shop journeys
===================================

The alluvial (Sankey) diagram follows sequences step by step: column :math:`t`
stacks the pages seen at step :math:`t`, ribbons carry visitors to the next
step, white boxes (``$``) collect those who left. Frequence (Perer & Wang, 2014)
popularized it for frequent event sequences. With an anchor, the diagram shows
what happens *after* a chosen pattern.
"""

import matplotlib.pyplot as plt

import spmviz as sv
from spmviz.viz import plot_sankey

db = sv.datasets.make_customer_journeys(1000, random_state=0)
plot_sankey(db, max_steps=5, top=6)
# %%
# After the cart
# --------------
plot_sankey(db, max_steps=4, top=5, anchor="cart", title="the four steps after the first visit to the cart")

# %%
# Parameter study: how many pages per column
# ------------------------------------------
fig, axes = plt.subplots(1, 2, figsize=(14, 5))
for ax, k in zip(axes, (3, 8)):
    plot_sankey(db, ax=ax, max_steps=4, top=k, title=f"top {k} pages per step")
plt.show()
