.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_arc_diagram.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 .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_arc_diagram.py: Les Miserables Arc Diagram =============================== This example shows how to create an arc diagram from a network. .. GENERATED FROM PYTHON SOURCE LINES 8-14 .. code-block:: Python import numpy as np import marsilea as ma import marsilea.plotter as mp .. GENERATED FROM PYTHON SOURCE LINES 19-21 Load data --------- .. GENERATED FROM PYTHON SOURCE LINES 21-29 .. code-block:: Python data = ma.load_data('les_miserables') nodes = data['nodes'] links = data['links'] sizes = nodes['value'].to_numpy().reshape(1, -1) colors = nodes['group'].to_numpy().reshape(1, -1) .. GENERATED FROM PYTHON SOURCE LINES 30-32 Create Arc Diagram ------------------ .. GENERATED FROM PYTHON SOURCE LINES 32-61 .. code-block:: Python palette = { 0: "#3C486B", 1: "#F0F0F0", 2: "#F9D949", 3: "#F45050", 4: "#F2E3DB", 5: "#41644A", 6: "#E86A33", 7: "#009FBD", 8: "#77037B", 9: "#4F4557", 10: "#B0DAFF" } link_colors = [palette[nodes.iloc[i].group] for i in links['source']] height = .5 width = height * len(nodes) / 3 sh = ma.SizedHeatmap(sizes, colors, palette=palette, sizes=(10, 200), frameon=False, height=height, width=width) sh.add_bottom(mp.Labels(nodes['name'], fontsize=8)) arc = mp.Arc(nodes.index, links.to_numpy(), colors=link_colors, lw=.5, alpha=.5) sh.add_top(arc, size=3) sh.add_title(bottom="Character relationships in Les Miserables", align="right", fontstyle="italic") sh.render() .. image-sg:: /auto_examples/images/sphx_glr_plot_arc_diagram_001.png :alt: plot arc diagram :srcset: /auto_examples/images/sphx_glr_plot_arc_diagram_001.png, /auto_examples/images/sphx_glr_plot_arc_diagram_001_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.142 seconds) .. _sphx_glr_download_auto_examples_plot_arc_diagram.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_arc_diagram.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_arc_diagram.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_