.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/network_science/plot_cliques.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_cliques.py: Cliques ============ This example from `igraph` shows how to compute and visualize cliques and highlight them. .. GENERATED FROM PYTHON SOURCE LINES 8-41 .. code-block:: Python import igraph as ig import matplotlib.pyplot as plt import iplotx as ipx g = ig.Graph.Famous("Zachary") layout = g.layout("auto") cliques = g.cliques(4, 4) fig, axs = plt.subplots(3, 4) axs = axs.ravel() for clique, ax in zip(cliques, axs): ipx.plot( network=g, grouping=ig.VertexCover(g, [clique]), layout=layout, ax=ax, style={ "vertex": { "size": 5, }, "edge": { "linewidth": 0.5, }, "grouping": { "facecolor": "yellow", }, }, ) axs[-1].axis("off") # Hide the last empty subplot .. image-sg:: /gallery/network_science/images/sphx_glr_plot_cliques_001.png :alt: plot cliques :srcset: /gallery/network_science/images/sphx_glr_plot_cliques_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (np.float64(0.0), np.float64(1.0), np.float64(0.0), np.float64(1.0)) .. GENERATED FROM PYTHON SOURCE LINES 42-46 Advanced: improving plotting style ---------------------------------- If you want a little more style, you can color the vertices/edges within each clique to make them stand out: .. GENERATED FROM PYTHON SOURCE LINES 46-84 .. code-block:: Python fig, axs = plt.subplots(3, 4) axs = axs.ravel() for clique, ax in zip(cliques, axs): # Color vertices yellow/red based on whether they are in this clique g.vs["color"] = "yellow" g.vs[clique]["color"] = "red" # Color edges black/red based on whether they are in this clique clique_edges = g.es.select(_within=clique) g.es["color"] = "black" clique_edges["color"] = "red" # also increase thickness of clique edges g.es["width"] = 0.3 clique_edges["width"] = 1 ipx.plot( network=g, grouping=ig.VertexCover(g, [clique]), layout=layout, ax=ax, style={ "vertex": { "size": 5, "facecolor": g.vs["color"], "edgecolor": "black", "linewidth": 0.5, }, "edge": { "linewidth": g.es["width"], "color": g.es["color"], }, "grouping": { "facecolor": "red", "vertexpadding": 3, }, }, ) axs[-1].axis("off") # Hide the last empty subplot .. image-sg:: /gallery/network_science/images/sphx_glr_plot_cliques_002.png :alt: plot cliques :srcset: /gallery/network_science/images/sphx_glr_plot_cliques_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (np.float64(0.0), np.float64(1.0), np.float64(0.0), np.float64(1.0)) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.774 seconds) .. _sphx_glr_download_gallery_network_science_plot_cliques.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_cliques.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_cliques.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_cliques.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_