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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_examples_plot-with-clim.py>`
        to download the full example code.

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

.. _sphx_glr_examples_plot-with-clim.py:


===============================
Plot with specified data limits
===============================

:meth:`.Convention.make_artist()` method will create an appropriate
:class:`~matplotlib.artist.Artist` to plot a variable.
The artist can be customised by passing kwargs to :meth:`~.Convention.make_artist()`.
The :meth:`~.Convention.make_artist()` documentation for each convention
will describe what artists are created for what kinds of variables.

Typically a scalar variable defined on a polygon grid
will be drawn using a :class:`~matplotlib.collections.PolyCollection`.
This class accepts options such as `clim` and `cmap`
which can be used to customise the appearance of the plot.

.. GENERATED FROM PYTHON SOURCE LINES 17-52



.. image-sg:: /examples/images/sphx_glr_plot-with-clim_001.png
   :alt: Sea surface height deviation
   :srcset: /examples/images/sphx_glr_plot-with-clim_001.png
   :class: sphx-glr-single-img





.. code-block:: Python

    import cartopy.crs
    import emsarray
    import emsarray.plot
    from emsarray.plot.shortcuts import monkeypatch_gshhs_downloader
    from cartopy.feature import GSHHSFeature
    from matplotlib import pyplot

    # Open the dataset
    ds = emsarray.tutorial.open_dataset('austen')

    # Make a figure
    figure = pyplot.figure(figsize=(10, 8), layout='constrained')
    axes = figure.add_subplot(projection=cartopy.crs.PlateCarree())
    axes.set_aspect('equal', adjustable='datalim')

    # Make an artist to plot eta
    eta_artist = ds.ems.make_artist(
        axes, ds['eta'].isel(record=0),
        add_colorbar=False,
        clim=(-3, 3), edgecolor='face', cmap='Spectral_r',
    )
    figure.colorbar(eta_artist, ax=axes, location='right', label="metres")

    # Draw some coastlines
    # Temporary workaround for https://github.com/SciTools/cartopy/pull/2659/changes
    monkeypatch_gshhs_downloader()
    coast = GSHHSFeature(scale='intermediate')
    axes.add_feature(coast, facecolor='linen', edgecolor='darkgrey', linewidth=0.5)

    # Finish setting up the plot
    axes.autoscale()
    axes.set_title("Sea surface height deviation")
    axes.set_facecolor('aliceblue')

    pyplot.show()


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

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


.. _sphx_glr_download_examples_plot-with-clim.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: plot-with-clim.ipynb <plot-with-clim.ipynb>`

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

      :download:`Download Python source code: plot-with-clim.py <plot-with-clim.py>`

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

      :download:`Download zipped: plot-with-clim.zip <plot-with-clim.zip>`


.. only:: html

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

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