.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/style/plot_tension.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_style_plot_tension.py: Edge tension ============ This example shows how to use edge tension to create curved edges with sharper turns. .. GENERATED FROM PYTHON SOURCE LINES 7-34 .. code-block:: Python import networkx as nx import iplotx as ipx tension = [0, 0.1, 0.5, 1.0, 2.0, 4.0, 8.0] G = nx.MultiGraph() G.add_edges_from([(0, 1)] * len(tension)) layout = { 0: (0, 0), 1: (1, 1), } ipx.network( G, layout=layout, edge_curved=True, edge_tension=tension, edge_labels=[str(x) if x > 0 else "" for x in tension], edge_label_bbox=dict( edgecolor="black", facecolor="white", boxstyle="round,pad=0.2", ), edge_label_rotate=False, ) .. image-sg:: /gallery/style/images/sphx_glr_plot_tension_001.png :alt: plot tension :srcset: /gallery/style/images/sphx_glr_plot_tension_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 35-36 Negative tension can be used too: .. GENERATED FROM PYTHON SOURCE LINES 36-51 .. code-block:: Python ipx.network( G, layout=layout, edge_curved=True, edge_tension=[-x for x in tension], edge_labels=[str(-x) if x > 0 else "" for x in tension], edge_label_bbox=dict( edgecolor="black", facecolor="white", boxstyle="round,pad=0.2", ), edge_label_rotate=False, ) .. image-sg:: /gallery/style/images/sphx_glr_plot_tension_002.png :alt: plot tension :srcset: /gallery/style/images/sphx_glr_plot_tension_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 52-53 For directed graphs, positive tension is always **to the right** when facing out in the edge direction .. GENERATED FROM PYTHON SOURCE LINES 53-75 .. code-block:: Python tension = [1.0, 3.0] Gd = nx.MultiDiGraph() Gd.add_edges_from([(0, 1)] * len(tension)) Gd.add_edges_from([(1, 0)] * len(tension)) ipx.network( Gd, layout=layout, edge_curved=True, edge_tension=tension * 2, edge_labels=[f"+{x}" if x > 0 else "" for x in tension] * 2, edge_label_bbox=dict( edgecolor="black", facecolor="white", boxstyle="round,pad=0.2", ), edge_label_rotate=False, aspect=1, ) .. image-sg:: /gallery/style/images/sphx_glr_plot_tension_003.png :alt: plot tension :srcset: /gallery/style/images/sphx_glr_plot_tension_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 76-80 .. tip:: For undirected graphs, the chirality (right/leftness) of the tension depends on whether the network library reorders the edge adjacent vertices (e.g. `networkx` does). Some trial and error on a specific plot should lead to the desired solution. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.130 seconds) .. _sphx_glr_download_gallery_style_plot_tension.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_tension.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_tension.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_tension.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_