.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/basic/plot_loops.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_basic_plot_loops.py: Loops ===== This minimal example shows how to style a plot loops. .. GENERATED FROM PYTHON SOURCE LINES 7-48 .. code-block:: Python import networkx as nx import iplotx as ipx # Create a graph and add a self-loop to node 0 G = nx.complete_graph(3, create_using=nx.DiGraph) pos = nx.circular_layout(G) ne = G.number_of_edges() # Add self-loops to the remaining nodes G.add_edge(0, 0) edgelist = [(1, 1), (2, 2)] G.add_edges_from(edgelist) # Style the edge lines linestyle = {e: "-" if e not in edgelist else "--" for e in G.edges()} ipx.network( G, layout=pos, vertex_labels=True, style={ "vertex": { "size": 30, "facecolor": "lightblue", "edgecolor": "none", "label": { "color": "black", }, }, "edge": { "linestyle": linestyle, "paralleloffset": 0, "looptension": 3.5, "arrow": { "marker": "|>", }, }, }, ) .. image-sg:: /gallery/basic/images/sphx_glr_plot_loops_001.png :alt: plot loops :srcset: /gallery/basic/images/sphx_glr_plot_loops_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 49-52 In addition to fully structured styles in the form of nested dictionaries, `iplotx` also accepts flat or semi-flat styles, with levels separated by underscores ("_"). The above is equivalent to: .. GENERATED FROM PYTHON SOURCE LINES 52-69 .. code-block:: Python ipx.network( G, layout=pos, vertex_labels=True, style=dict( vertex_size=30, vertex_facecolor="lightblue", vertex_edgecolor="none", vertex_label_color="black", edge_linestyle=linestyle, edge_paralleloffset=0, edge_looptension=3.5, edge_arrow_marker="|>", ), ) .. image-sg:: /gallery/basic/images/sphx_glr_plot_loops_002.png :alt: plot loops :srcset: /gallery/basic/images/sphx_glr_plot_loops_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 70-72 The `**kwargs` flexible argument of `ipx.plotting` can be used for this purpose as well, for increased readability: .. GENERATED FROM PYTHON SOURCE LINES 72-87 .. code-block:: Python ipx.network( G, layout=pos, vertex_labels=True, vertex_size=30, vertex_facecolor="lightblue", vertex_edgecolor="none", vertex_label_color="black", edge_linestyle=linestyle, edge_paralleloffset=0, edge_looptension=3.5, edge_arrow_marker="|>", ) .. image-sg:: /gallery/basic/images/sphx_glr_plot_loops_003.png :alt: plot loops :srcset: /gallery/basic/images/sphx_glr_plot_loops_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 88-89 The same can be achieved also with a style **context**: .. GENERATED FROM PYTHON SOURCE LINES 89-105 .. code-block:: Python with ipx.style.context( vertex_size=30, vertex_facecolor="lightblue", vertex_edgecolor="none", vertex_label_color="black", edge_linestyle=linestyle, edge_paralleloffset=0, edge_looptension=3.5, edge_arrow_marker="|>", ): ipx.network( G, layout=pos, vertex_labels=True, ) .. image-sg:: /gallery/basic/images/sphx_glr_plot_loops_004.png :alt: plot loops :srcset: /gallery/basic/images/sphx_glr_plot_loops_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.161 seconds) .. _sphx_glr_download_gallery_basic_plot_loops.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_loops.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_loops.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_loops.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_