Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Sankey diagram of web-shop journeys#
The alluvial (Sankey) diagram follows sequences step by step: column \(t\)
stacks the pages seen at step \(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)

<Axes: title={'left': 'Sankey diagram of 1000 sequences'}>
After the cart#
plot_sankey(db, max_steps=4, top=5, anchor="cart", title="the four steps after the first visit to the cart")

<Axes: title={'left': '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()

Total running time of the script: (0 minutes 0.367 seconds)