.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_graph_structure_plot_chord_diagram.py>`     to download the full example code
    .. rst-class:: sphx-glr-example-title

    .. _sphx_glr_gallery_graph_structure_plot_chord_diagram.py:


Chord diagram
=============



.. image:: /gallery/graph_structure/images/sphx_glr_plot_chord_diagram_001.png
    :alt: plot chord diagram
    :class: sphx-glr-single-img






.. code-block:: default


    import matplotlib.pyplot as plt

    import nngt


    nngt.seed(0)


    # create a structured graph

    room1 = nngt.Group(25)
    room2 = nngt.Group(50)
    room3 = nngt.Group(40)
    room4 = nngt.Group(35)

    names = ["R1", "R2", "R3", "R4"]

    struct = nngt.Structure.from_groups((room1, room2, room3, room4), names)

    g = nngt.Graph(structure=struct)

    for room in struct:
        nngt.generation.connect_groups(g, room, room, "all_to_all")

    nngt.generation.connect_groups(g, (room1, room2), struct, "erdos_renyi",
                                   avg_deg=10, ignore_invalid=True)

    nngt.generation.connect_groups(g, room3, room1, "erdos_renyi", avg_deg=20)

    nngt.generation.connect_groups(g, room4, room3, "erdos_renyi", avg_deg=10)


    # get the structure graph and plot

    sg = g.get_structure_graph()

    nngt.plot.chord_diagram(sg, names="name", sort="distance",
                            use_gradient=True, show=True)


.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download_gallery_graph_structure_plot_chord_diagram.py:


.. only :: html

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



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

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



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

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


.. only:: html

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

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