.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_trees/plot_03_word_tree.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_03_trees_plot_03_word_tree.py: Word trees around a pivot ========================= A double tree puts one event in the middle and grows two trees from it: the steps that follow its first occurrence (right) and those that precede it (left, read backwards). Font size and line width encode the number of sequences. It is the view of choice for questions like *what happens before and after a visitor adds something to the cart?* — and works just as well for melodies. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv from spmviz.viz import plot_double_tree shop = sv.datasets.make_customer_journeys(1000, random_state=0) plot_double_tree(shop, "cart", max_depth=3, min_count=15) .. image-sg:: /auto_examples/03_trees/images/sphx_glr_plot_03_word_tree_001.png :alt: double tree around cart (320 sequences) :srcset: /auto_examples/03_trees/images/sphx_glr_plot_03_word_tree_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 19-21 Melodies: what surrounds the motif "E D C"? ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python songs = sv.datasets.load_melodies("phrase") plot_double_tree(songs, "E D C", max_depth=3, min_count=1, top_children=4) .. image-sg:: /auto_examples/03_trees/images/sphx_glr_plot_03_word_tree_002.png :alt: double tree around E → D → C (17 sequences) :srcset: /auto_examples/03_trees/images/sphx_glr_plot_03_word_tree_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: a longer pivot ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-29 .. code-block:: Python plot_double_tree(shop, "product cart", max_depth=2, min_count=10) plt.show() .. image-sg:: /auto_examples/03_trees/images/sphx_glr_plot_03_word_tree_003.png :alt: double tree around product → cart (320 sequences) :srcset: /auto_examples/03_trees/images/sphx_glr_plot_03_word_tree_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.253 seconds) .. _sphx_glr_download_auto_examples_03_trees_plot_03_word_tree.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/03_trees/plot_03_word_tree.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_word_tree.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_word_tree.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_word_tree.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_