
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/specialty_plots/sankey_links.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_specialty_plots_sankey_links.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_specialty_plots_sankey_links.py:


======================================
Long chain of connections using Sankey
======================================

Demonstrate/test the Sankey class by producing a long chain of connections.

.. GENERATED FROM PYTHON SOURCE LINES 8-60

.. code-block:: Python


    import matplotlib.pyplot as plt

    from matplotlib.sankey import Sankey

    links_per_side = 6


    def side(sankey, n=1):
        """Generate a side chain."""
        prior = len(sankey.diagrams)
        for i in range(0, 2*n, 2):
            sankey.add(flows=[1, -1], orientations=[-1, -1],
                       patchlabel=str(prior + i),
                       prior=prior + i - 1, connect=(1, 0), alpha=0.5)
            sankey.add(flows=[1, -1], orientations=[1, 1],
                       patchlabel=str(prior + i + 1),
                       prior=prior + i, connect=(1, 0), alpha=0.5)


    def corner(sankey):
        """Generate a corner link."""
        prior = len(sankey.diagrams)
        sankey.add(flows=[1, -1], orientations=[0, 1],
                   patchlabel=str(prior), facecolor='k',
                   prior=prior - 1, connect=(1, 0), alpha=0.5)


    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[],
                         title="Why would you want to do this?\n(But you could.)")
    sankey = Sankey(ax=ax, unit=None)
    sankey.add(flows=[1, -1], orientations=[0, 1],
               patchlabel="0", facecolor='k',
               rotation=45)
    side(sankey, n=links_per_side)
    corner(sankey)
    side(sankey, n=links_per_side)
    corner(sankey)
    side(sankey, n=links_per_side)
    corner(sankey)
    side(sankey, n=links_per_side)
    sankey.finish()
    # Notice:
    # 1. The alignment doesn't drift significantly (if at all; with 16007
    #    subdiagrams there is still closure).
    # 2. The first diagram is rotated 45 deg, so all other diagrams are rotated
    #    accordingly.

    plt.show()





.. image-sg:: /gallery/specialty_plots/images/sphx_glr_sankey_links_001.png
   :alt: Why would you want to do this? (But you could.)
   :srcset: /gallery/specialty_plots/images/sphx_glr_sankey_links_001.png, /gallery/specialty_plots/images/sphx_glr_sankey_links_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 61-70

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.sankey`
   - `matplotlib.sankey.Sankey`
   - `matplotlib.sankey.Sankey.add`
   - `matplotlib.sankey.Sankey.finish`


.. _sphx_glr_download_gallery_specialty_plots_sankey_links.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: sankey_links.ipynb <sankey_links.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: sankey_links.py <sankey_links.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: sankey_links.zip <sankey_links.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
