:orphan:

.. _gallery-of-examples:

Gallery of Examples
===================

Gallery of examples for `python-igraph` illustrating graph generation, analysis, and plotting.

Impatient? Check out the :ref:`tutorials-quickstart`.

Too little detail? Read the :doc:`extended tutorial <../tutorial>`.



.. raw:: html

    <div class="sphx-glr-thumbnails">

.. thumbnail-parent-div-open

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to create a random directed acyclic graph (DAG), which is useful in a number of contexts including for Git commit history.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_generate_dag_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_generate_dag.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Directed Acyclic Graph</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to visualise the connected components in a graph using igraph.GraphBase.connected_components.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_connected_components_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_connected_components.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Connected Components</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to use igraph&#x27;s configuration instance &lt;igraph.Configuration&gt; to set default igraph settings. This is useful for setting global settings so that they don&#x27;t need to be explicitly stated at the beginning of every igraph project you work on.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_configuration_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_configuration.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Configuration Instance</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to compute and visualize the articulation points in a graph using igraph.GraphBase.articulation_points. For an example on bridges instead, see tutorials-bridges.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_articulation_points_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_articulation_points.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Articulation Points</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to construct a max flow on a directed graph with edge capacities using igraph.Graph.maxflow.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_maxflow_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_maxflow.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Maximum Flow</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to generate a minimum spanning tree from an input graph using igraph.Graph.spanning_tree. If you only need a regular spanning tree, check out tutorials-spanning-trees.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_minimum_spanning_trees_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_minimum_spanning_trees.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Minimum Spanning Trees</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to generate a spanning tree from an input graph using igraph.Graph.spanning_tree. For the related idea of finding a minimum spanning tree, see tutorials-minimum-spanning-trees.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_spanning_trees_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_spanning_trees.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Spanning Trees</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to generate the complement graph of a graph (sometimes known as the anti-graph) using igraph.GraphBase.complementer.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_complement_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_complement.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Complement</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates an efficient way to find and visualise a maximum biparite matching using igraph.Graph.maximum_bipartite_matching.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_bipartite_matching_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_bipartite_matching.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Maximum Bipartite Matching</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to get a topological sorting on a directed acyclic graph (DAG). A topological sorting of a directed graph is a linear ordering based on the precedence implied by the directed edges. It exists iff the graph doesn&#x27;t have any cycle. In igraph, we can use igraph.GraphBase.topological_sorting to get a topological ordering of the vertices.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_topological_sort_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_topological_sort.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Topological sorting</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to visualize communities or clusters of a graph.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_visualize_communities_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_visualize_communities.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Communities</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to generate Erdős–Rényi graphs using igraph.GraphBase.Erdos_Renyi. There are two variants of graphs:">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_erdos_renyi_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_erdos_renyi.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Erdős-Rényi Graph</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to change the visual style of network plots.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_visual_style_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_visual_style.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Visual styling</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to remove self loops and multiple edges using igraph.GraphBase.simplify.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_simplify_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_simplify.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Simplify</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to compute and visualize cliques of a graph using igraph.GraphBase.cliques.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_visualize_cliques_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_visualize_cliques.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Cliques</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example presents how to visualise bipartite matching using maximum flow (see igraph.Graph.maxflow).">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_bipartite_matching_maxflow_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_bipartite_matching_maxflow.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Maximum Bipartite Matching by Maximum Flow</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to find the shortest distance between two vertices of a weighted or an unweighted graph.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_shortest_path_visualisation_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_shortest_path_visualisation.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Shortest Paths</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to calculate the Delaunay triangulation of an input graph. We start by generating a set of points on a 2D grid using random numpy arrays and a graph with those vertex coordinates and no edges.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_delaunay-triangulation_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_delaunay-triangulation.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Delaunay Triangulation</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to compute and visualize the bridges in a graph using igraph.GraphBase.bridges. For an example on articulation points instead, see tutorials-articulation-points.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_bridges_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_bridges.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Bridges</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to use matplotlib:api/animation_api in order to animate a ring graph sequentially being revealed.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_ring_animation_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_ring_animation.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Ring Graph Animation</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to check for isomorphism between small graphs using igraph.GraphBase.isomorphic.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_isomorphism_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_isomorphism.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Isomorphism</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="- Construct a graph - Set attributes of nodes and edges - Plot a graph using matplotlib - Save the plot as an image - Export and import a graph as a .gml file">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_quickstart_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_quickstart.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Quick Start</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to calculate and visualize personalized PageRank on a grid. We use the igraph.Graph.personalized_pagerank method, and demonstrate the effects on a grid graph.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_personalized_pagerank_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_personalized_pagerank.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Personalized PageRank on a grid</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to find the communities in a graph, then contract each community into a single node using igraph.clustering.VertexClustering. For this tutorial, we&#x27;ll use the Donald Knuth&#x27;s Les Miserables Network, which shows the coapperances of characters in the novel Les Miserables.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_cluster_contraction_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_cluster_contraction.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Generating Cluster Graphs</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example reproduces a typical data science situation in an internet company. We start from a pandas DataFrame with online user actions, for instance for an online text editor: the user can create a page, edit it, or delete it. We want to construct and visualize a graph of the users highlighting collaborations on the same page/project.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_online_user_actions_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_online_user_actions.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Online user actions</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates how to visualize both vertex and edge betweenness with a custom defined color palette. We use the methods igraph.GraphBase.betweenness and igraph.GraphBase.edge_betweenness respectively, and demonstrate the effects on a standard Krackhardt Kite graph, as well as a Watts-Strogatz random graph.">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_betweenness_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_betweenness.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Betweenness</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example demonstrates the use of stochastic community detection methods to check whether a network possesses a strong community structure, and whether the partitionings we obtain are meaningul. Many community detection algorithms are randomized, and return somewhat different results after each run, depending on the random seed that was set. When there is a robust community structure, we expect these results to be similar to each other. When the community structure is weak or non-existent, the results may be noisy and highly variable. We will employ several partion similarity measures to analyse the consistency of the results, including the normalized mutual information (NMI), the variation of information (VI), and the Rand index (RI).">

.. only:: html

  .. image:: /tutorials/images/thumb/sphx_glr_stochastic_variability_thumb.png
    :alt:

  :ref:`sphx_glr_tutorials_stochastic_variability.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Stochastic Variability in Community Detection Algorithms</div>
    </div>


.. thumbnail-parent-div-close

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /tutorials/generate_dag
   /tutorials/connected_components
   /tutorials/configuration
   /tutorials/articulation_points
   /tutorials/maxflow
   /tutorials/minimum_spanning_trees
   /tutorials/spanning_trees
   /tutorials/complement
   /tutorials/bipartite_matching
   /tutorials/topological_sort
   /tutorials/visualize_communities
   /tutorials/erdos_renyi
   /tutorials/visual_style
   /tutorials/simplify
   /tutorials/visualize_cliques
   /tutorials/bipartite_matching_maxflow
   /tutorials/shortest_path_visualisation
   /tutorials/delaunay-triangulation
   /tutorials/bridges
   /tutorials/ring_animation
   /tutorials/isomorphism
   /tutorials/quickstart
   /tutorials/personalized_pagerank
   /tutorials/cluster_contraction
   /tutorials/online_user_actions
   /tutorials/betweenness
   /tutorials/stochastic_variability


.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-gallery

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download all examples in Python source code: tutorials_python.zip </tutorials/tutorials_python.zip>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download all examples in Jupyter notebooks: tutorials_jupyter.zip </tutorials/tutorials_jupyter.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
