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

.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_graph_structure_plot_map.py>`
        to download the full example code

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

.. _sphx_glr_gallery_graph_structure_plot_map.py:


Geospatial networks
===================

.. GENERATED FROM PYTHON SOURCE LINES 24-68



.. image-sg:: /gallery/graph_structure/images/sphx_glr_plot_map_001.png
   :alt: plot map
   :srcset: /gallery/graph_structure/images/sphx_glr_plot_map_001.png
   :class: sphx-glr-single-img





.. code-block:: default


    import os

    import cartopy.crs as ccrs
    import matplotlib.pyplot as plt
    import numpy as np

    import nngt
    import nngt.geospatial as ng


    plt.rcParams.update({
        'axes.edgecolor': 'grey', 'xtick.color': 'grey', 'ytick.color': 'grey',
        "figure.facecolor": (0, 0, 0, 0), "axes.facecolor": (0, 0, 0, 0),
        "axes.labelcolor": "grey", "text.color": "grey"
    })


    nngt.seed(2)


    # take random countries
    num_nodes = 20

    world = ng.maps["adaptive"]
    units = nngt._rng.choice(50, num_nodes, replace=False)
    codes = list(world.iloc[units].SU_A3)

    # make random network
    g = nngt.generation.erdos_renyi(nodes=num_nodes, avg_deg=3)

    # add the A3 code for each country (that's the crucial part that will link
    # the graph to the geospatial data)
    g.new_node_attribute("code", "string", codes)

    g.set_weights(nngt._rng.exponential(2, g.edge_nb()))

    # plot using draw_map and the A3 codes stored in "code"
    ng.draw_map(g, "code", ncolor="in-degree", esize="weight", threshold=0,
                ecolor="grey", proj=ccrs.EqualEarth(), max_nsize=20, show=False)

    if nngt.get_config("with_plot"):
        plt.tight_layout()
        plt.show()


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

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


.. _sphx_glr_download_gallery_graph_structure_plot_map.py:


.. only :: html

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



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

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



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

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


.. only:: html

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

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