.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/network_science/plot_multipartite_layout.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_gallery_network_science_plot_multipartite_layout.py: Multipartite layout =================== This example from networkx shows how to use simple vertex styling. .. GENERATED FROM PYTHON SOURCE LINES 7-52 .. image-sg:: /gallery/network_science/images/sphx_glr_plot_multipartite_layout_001.png :alt: plot multipartite layout :srcset: /gallery/network_science/images/sphx_glr_plot_multipartite_layout_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] | .. code-block:: Python import itertools import matplotlib.pyplot as plt import networkx as nx import iplotx as ipx subset_sizes = [5, 5, 4, 3, 2, 4, 4, 3] subset_color = [ "gold", "violet", "violet", "violet", "violet", "limegreen", "limegreen", "darkorange", ] def multilayered_graph(*subset_sizes): extents = nx.utils.pairwise(itertools.accumulate((0,) + subset_sizes)) layers = [range(start, end) for start, end in extents] G = nx.Graph() for i, layer in enumerate(layers): G.add_nodes_from(layer, layer=i) for layer1, layer2 in nx.utils.pairwise(layers): G.add_edges_from(itertools.product(layer1, layer2)) return G G = multilayered_graph(*subset_sizes) color = [subset_color[data["layer"]] for v, data in G.nodes(data=True)] pos = nx.multipartite_layout(G, subset_key="layer") fig, ax = plt.subplots(figsize=(6, 4)) ipx.plot( G, layout=pos, style={ "vertex": { "facecolor": color, }, }, ax=ax, ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.109 seconds) .. _sphx_glr_download_gallery_network_science_plot_multipartite_layout.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_multipartite_layout.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_multipartite_layout.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_multipartite_layout.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_