.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "sphinx_gallery_output/plot_17_multipartite_layout.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_sphinx_gallery_output_plot_17_multipartite_layout.py: Multi-partite & shell node layouts ================================== Draw a multi-partite in successive layers or in concentric circles. .. GENERATED FROM PYTHON SOURCE LINES 10-12 To draw a multi-partite graph in successive layers, use the :code:`multipartite` node layout. The :code:`layers` argument indicates in which layer each node is plotted, as well as the order of layers. .. GENERATED FROM PYTHON SOURCE LINES 12-33 .. code-block:: default import numpy as np import matplotlib.pyplot as plt from netgraph import Graph partitions = [ list(range(3)), list(range(3, 9)), list(range(9, 21)) ] edges = list(zip(np.repeat(partitions[0], 2), partitions[1])) \ + list(zip(np.repeat(partitions[0], 2), partitions[1][1:])) \ + list(zip(np.repeat(partitions[1], 2), partitions[2])) \ + list(zip(np.repeat(partitions[1], 2), partitions[2][1:])) Graph(edges, node_layout='multipartite', node_layout_kwargs=dict(layers=partitions, reduce_edge_crossings=True), node_labels=True) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_17_multipartite_layout_001.png :alt: plot 17 multipartite layout :srcset: /sphinx_gallery_output/images/sphx_glr_plot_17_multipartite_layout_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/paul/src/netgraph/netgraph/_parser.py:23: UserWarning: Multi-graphs are not properly supported. Duplicate edges are plotted as a single edge; edge weights (if any) are summed. warnings.warn(msg) :6: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray .. GENERATED FROM PYTHON SOURCE LINES 34-36 To change the layout from the left-right orientation to a bottom-up orientation, call the layout function directly and swap x and y coordinates of the node positions. .. GENERATED FROM PYTHON SOURCE LINES 36-60 .. code-block:: default import numpy as np import matplotlib.pyplot as plt from netgraph import Graph, get_multipartite_layout partitions = [ list(range(3)), list(range(3, 9)), list(range(9, 21)) ] edges = list(zip(np.repeat(partitions[0], 2), partitions[1])) \ + list(zip(np.repeat(partitions[0], 2), partitions[1][1:])) \ + list(zip(np.repeat(partitions[1], 2), partitions[2])) \ + list(zip(np.repeat(partitions[1], 2), partitions[2][1:])) node_positions = get_multipartite_layout(edges, partitions, reduce_edge_crossings=True) node_positions = {node : (x, y) for node, (y, x) in node_positions.items()} Graph(edges, node_layout=node_positions, node_labels=True) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_17_multipartite_layout_002.png :alt: plot 17 multipartite layout :srcset: /sphinx_gallery_output/images/sphx_glr_plot_17_multipartite_layout_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none :6: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray /home/paul/src/netgraph/netgraph/_parser.py:23: UserWarning: Multi-graphs are not properly supported. Duplicate edges are plotted as a single edge; edge weights (if any) are summed. warnings.warn(msg) .. GENERATED FROM PYTHON SOURCE LINES 61-63 To draw a multi-partite graph in concentric circles, use the :code:`shell` node layout. The :code:`shells` argument indicates in which circle each node is plotted, as well as the order of shells. .. GENERATED FROM PYTHON SOURCE LINES 63-83 .. code-block:: default import numpy as np import matplotlib.pyplot as plt from netgraph import Graph partitions = [ list(range(3)), list(range(3, 9)), list(range(9, 21)) ] edges = list(zip(np.repeat(partitions[0], 2), partitions[1])) \ + list(zip(np.repeat(partitions[0], 2), partitions[1][1:])) \ + list(zip(np.repeat(partitions[1], 2), partitions[2])) \ + list(zip(np.repeat(partitions[1], 2), partitions[2][1:])) Graph(edges, node_layout='shell', node_layout_kwargs=dict(shells=partitions, reduce_edge_crossings=True), node_labels=True) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_17_multipartite_layout_003.png :alt: plot 17 multipartite layout :srcset: /sphinx_gallery_output/images/sphx_glr_plot_17_multipartite_layout_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/paul/src/netgraph/netgraph/_parser.py:23: UserWarning: Multi-graphs are not properly supported. Duplicate edges are plotted as a single edge; edge weights (if any) are summed. warnings.warn(msg) :6: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.550 seconds) .. _sphx_glr_download_sphinx_gallery_output_plot_17_multipartite_layout.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_17_multipartite_layout.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_17_multipartite_layout.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_