.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_flows/plot_01_sankey.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_04_flows_plot_01_sankey.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 11-19 .. code-block:: Python 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) .. image-sg:: /auto_examples/04_flows/images/sphx_glr_plot_01_sankey_001.png :alt: Sankey diagram of 1000 sequences :srcset: /auto_examples/04_flows/images/sphx_glr_plot_01_sankey_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 20-22 After the cart -------------- .. GENERATED FROM PYTHON SOURCE LINES 22-24 .. code-block:: Python plot_sankey(db, max_steps=4, top=5, anchor="cart", title="the four steps after the first visit to the cart") .. image-sg:: /auto_examples/04_flows/images/sphx_glr_plot_01_sankey_002.png :alt: the four steps after the first visit to the cart :srcset: /auto_examples/04_flows/images/sphx_glr_plot_01_sankey_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 25-27 Parameter study: how many pages per column ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 27-31 .. code-block:: Python 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() .. image-sg:: /auto_examples/04_flows/images/sphx_glr_plot_01_sankey_003.png :alt: top 3 pages per step, top 8 pages per step :srcset: /auto_examples/04_flows/images/sphx_glr_plot_01_sankey_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.297 seconds) .. _sphx_glr_download_auto_examples_04_flows_plot_01_sankey.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/spmviz/main?urlpath=lab/tree/notebooks/auto_examples/04_flows/plot_01_sankey.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_sankey.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_sankey.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_sankey.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_