.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/network_science/plot_minimum_spanning_trees.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_minimum_spanning_trees.py: Minimum spanning trees ====================== This example from igraph shows how to work with edge labels and linewidths. .. GENERATED FROM PYTHON SOURCE LINES 7-49 .. code-block:: Python import random import igraph as ig import iplotx as ipx random.seed(0) g = ig.Graph.Lattice([5, 5], circular=False) g.es["weight"] = [random.randint(1, 20) for _ in g.es] mst_edges = g.spanning_tree(weights=g.es["weight"], return_tree=False) g.es["color"] = "lightgray" g.es[mst_edges]["color"] = "midnightblue" g.es["width"] = 1.0 g.es[mst_edges]["width"] = 3.0 layout = g.layout("grid") ipx.network( g, layout=layout, edge_labels=g.es["weight"], style={ "vertex": { "facecolor": "lightblue", "edgecolor": "black", "linewidth": 1, }, "edge": { "linewidth": g.es["width"], "label": { "rotate": True, "bbox": { "facecolor": "white", "edgecolor": "none", }, }, }, }, ) .. image-sg:: /gallery/network_science/images/sphx_glr_plot_minimum_spanning_trees_001.png :alt: plot minimum spanning trees :srcset: /gallery/network_science/images/sphx_glr_plot_minimum_spanning_trees_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 50-53 If you want to avoid rotating the labels vertically and let them follow the edge directions instead, just set the "rotate" parameter to False (or skip it in the default style): .. GENERATED FROM PYTHON SOURCE LINES 53-76 .. code-block:: Python ipx.network( g, layout=layout, edge_labels=g.es["weight"], style={ "vertex": { "facecolor": "lightblue", "edgecolor": "black", "linewidth": 1, }, "edge": { "linewidth": g.es["width"], "label": { "rotate": False, "bbox": { "facecolor": "white", "edgecolor": "none", }, }, }, }, ) .. image-sg:: /gallery/network_science/images/sphx_glr_plot_minimum_spanning_trees_002.png :alt: plot minimum spanning trees :srcset: /gallery/network_science/images/sphx_glr_plot_minimum_spanning_trees_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.194 seconds) .. _sphx_glr_download_gallery_network_science_plot_minimum_spanning_trees.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_minimum_spanning_trees.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_minimum_spanning_trees.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_minimum_spanning_trees.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_