.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "sphinx_gallery_output/plot_04_weighted.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_04_weighted.py: Weighted Graphs (2) =================== Alternative visualisation for a weighted graph using edge widths to represent the absolute edge weight, and colour to represent the sign of the weight. .. GENERATED FROM PYTHON SOURCE LINES 9-38 .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_04_weighted_001.png :alt: plot 04 weighted :srcset: /sphinx_gallery_output/images/sphx_glr_plot_04_weighted_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/paul/src/netgraph/netgraph/_utils.py:394: RuntimeWarning: invalid value encountered in true_divide unit_vector = vector / np.linalg.norm(vector) | .. code-block:: default import numpy as np import matplotlib.pyplot as plt from netgraph import Graph weighted_cube = [ (0, 1, -0.1), (1, 2, -0.2), (2, 3, -0.4), (3, 2, 0.0), (3, 0, -0.2), (4, 5, 0.7), (5, 6, 0.9), (6, 5, -0.2), (6, 7, 0.5), (7, 4, 0.1), (0, 4, 0.5), (1, 5, -0.3), (5, 1, -0.4), (2, 6, 0.8), (3, 7, 0.4) ] edge_width = {(u, v) : 3 * np.abs(w) for (u, v, w) in weighted_cube} edge_color = {(u, v) : 'blue' if w <=0 else 'red' for (u, v, w) in weighted_cube} Graph(weighted_cube, edge_width=edge_width, edge_color=edge_color, arrows=True) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.136 seconds) .. _sphx_glr_download_sphinx_gallery_output_plot_04_weighted.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_04_weighted.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_weighted.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_