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

.. only:: html

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

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

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

.. _sphx_glr_examples_vectors_plot_natural_earth.py:


Natural Earth and GeoPandas
===========================

Demonstrate use of GeoPandas to highlight particular Natural Earth features.

.. GENERATED FROM PYTHON SOURCE LINES 11-54



.. image-sg:: /examples/vectors/images/sphx_glr_plot_natural_earth_001.png
   :alt: Natural Earth with Geopandas
   :srcset: /examples/vectors/images/sphx_glr_plot_natural_earth_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /home/docs/checkouts/readthedocs.org/user_builds/hyoga/envs/stable/lib/python3.12/site-packages/hyoga/open/example.py:29: FutureWarning: In a future version, xarray will not decode timedelta values based on the presence of a timedelta-like units attribute by default. Instead it will rely on the presence of a timedelta64 dtype attribute, which is now xarray's default way of encoding timedelta64 values. To continue decoding timedeltas based on the presence of a timedelta-like units attribute, users will need to explicitly opt-in by passing True or CFTimedeltaCoder(decode_via_units=True) to decode_timedelta. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.
      return xr.open_dataset(path)
    /home/docs/checkouts/readthedocs.org/user_builds/hyoga/envs/stable/lib/python3.12/site-packages/shapely/constructive.py:829: RuntimeWarning: invalid value encountered in normalize
      return lib.normalize(geometry, **kwargs)
    /home/docs/checkouts/readthedocs.org/user_builds/hyoga/envs/stable/lib/python3.12/site-packages/shapely/constructive.py:829: RuntimeWarning: invalid value encountered in normalize
      return lib.normalize(geometry, **kwargs)
    /home/docs/checkouts/readthedocs.org/user_builds/hyoga/envs/stable/lib/python3.12/site-packages/shapely/constructive.py:829: RuntimeWarning: invalid value encountered in normalize
      return lib.normalize(geometry, **kwargs)
    /home/docs/checkouts/readthedocs.org/user_builds/hyoga/envs/stable/lib/python3.12/site-packages/shapely/constructive.py:829: RuntimeWarning: invalid value encountered in normalize
      return lib.normalize(geometry, **kwargs)
    downloading https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_admin_0_countries.zip...
    downloading https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_admin_1_states_provinces.zip...






|

.. code-block:: Python


    import matplotlib.pyplot as plt
    import hyoga


    # initialize figure
    ax = plt.subplot()

    # plot demo bedrock altitude
    with hyoga.open.example('pism.alps.out.2d.nc') as ds:
        ds.hyoga.plot.bedrock_altitude(ax=ax, vmin=0)

        # plot canonical Natural Earth background
        ds.hyoga.plot.natural_earth(ax=ax)

        # get dataset crs, we need this
        crs = ds.proj4

    # lock axes extent
    ax.set_autoscale_on(False)

    # plot the Po river and Lago di Garda in blue
    rivers = hyoga.open.natural_earth('rivers_lake_centerlines')
    rivers[rivers.name == 'Po'].to_crs(crs).plot(ax=ax, edgecolor='tab:blue')
    lakes = hyoga.open.natural_earth('lakes')
    lakes[lakes.name == 'Lago di Garda'].to_crs(crs).plot(ax=ax)

    # plot the outline of Switzerland in red
    countries = hyoga.open.natural_earth('admin_0_countries', category='cultural')
    countries[countries.NAME == 'Switzerland'].to_crs(crs).plot(
        ax=ax, edgecolor='tab:red', facecolor='none', linewidth=2)

    # plot Austria's Salzburg state in green
    states = hyoga.open.natural_earth(
        'admin_1_states_provinces', category='cultural')
    states[states.name == 'Salzburg'].to_crs(crs).plot(
        ax=ax, alpha=0.75, facecolor='tab:green')

    # set title
    ax.set_title('Natural Earth with Geopandas')

    # show
    plt.show()


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

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


.. _sphx_glr_download_examples_vectors_plot_natural_earth.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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