
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorials/configuration.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_tutorials_configuration.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_tutorials_configuration.py:


.. _tutorials-configuration:

======================
Configuration Instance
======================

This example shows how to use igraph's :class:`configuration instance <igraph.Configuration>` to set default igraph settings. This is useful for setting global settings so that they don't need to be explicitly stated at the beginning of every igraph project you work on.

.. GENERATED FROM PYTHON SOURCE LINES 10-15

.. code-block:: Python


    import igraph as ig
    import matplotlib.pyplot as plt
    import random








.. GENERATED FROM PYTHON SOURCE LINES 16-17

First we define the default plotting backend, layout, and color palette.

.. GENERATED FROM PYTHON SOURCE LINES 17-21

.. code-block:: Python

    ig.config["plotting.backend"] = "matplotlib"
    ig.config["plotting.layout"] = "fruchterman_reingold"
    ig.config["plotting.palette"] = "rainbow"








.. GENERATED FROM PYTHON SOURCE LINES 22-26

The updated configuration affects only the current session. Optionally, it
can be saved using ``ig.config.save()``. By default, this function writes the
configuration to ``~/.igraphrc`` on Linux and Max OS X systems, and in
``%USERPROFILE%\.igraphrc`` on Windows systems.

.. GENERATED FROM PYTHON SOURCE LINES 28-32

The configuration only needs to be saved to `.igraphrc` once, and it will
be automatically used in all future sessions. Whenever you use igraph and
this file exists, igraph will read its content and use those options as
defaults. For example, let's create and plot a new graph to demonstrate:

.. GENERATED FROM PYTHON SOURCE LINES 32-35

.. code-block:: Python

    random.seed(1)
    g = ig.Graph.Barabasi(n=100, m=1)








.. GENERATED FROM PYTHON SOURCE LINES 36-38

We now calculate a color value between 0-200 for all nodes, for instance by
computing the vertex betweenness:

.. GENERATED FROM PYTHON SOURCE LINES 38-41

.. code-block:: Python

    betweenness = g.betweenness()
    colors = [int(i * 200 / max(betweenness)) for i in betweenness]








.. GENERATED FROM PYTHON SOURCE LINES 42-44

Finally, we can plot the graph. You will notice that even though we did not
create a dedicated figure and axes, matplotlib is now used by default:

.. GENERATED FROM PYTHON SOURCE LINES 44-47

.. code-block:: Python

    ig.plot(g, vertex_color=colors, vertex_size=15, edge_width=0.3)
    plt.show()




.. image-sg:: /tutorials/images/sphx_glr_configuration_001.png
   :alt: configuration
   :srcset: /tutorials/images/sphx_glr_configuration_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 48-62

The full list of config settings can be found at
:class:`igraph.Configuration`.

.. note::

   You can have multiple config files: specify each location via
   ``ig.config.save("./path/to/config/file")``. To load a specific config,
   import igraph and then call ``ig.config.load("./path/to/config/file")``


.. note::

    To use a consistent style between individual plots (e.g. vertex sizes,
    colors, layout etc.) check out :ref:`tutorials-visual-style`.


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.210 seconds)


.. _sphx_glr_download_tutorials_configuration.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

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

      :download:`Download Jupyter notebook: configuration.ipynb <configuration.ipynb>`

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

      :download:`Download Python source code: configuration.py <configuration.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: configuration.zip <configuration.zip>`


.. only:: html

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

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