
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/plot-two-subplots.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-two-subplots.py>`
        to download the full example code.

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

.. _sphx_glr_examples_plot-two-subplots.py:


============================
Multiple plots in one figure
============================

.. GENERATED FROM PYTHON SOURCE LINES 6-43



.. image-sg:: /examples/images/sphx_glr_plot-two-subplots_001.png
   :alt: Sea surface height in the Timor Sea, 2017-03-01 00:00 +10:00, 2017-03-01 23:00 +10:00
   :srcset: /examples/images/sphx_glr_plot-two-subplots_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    from matplotlib import pyplot
    import emsarray
    from emsarray.utils import datetime_from_np_time
    from emsarray.plot import add_coast

    ds = emsarray.tutorial.open_dataset('austen')
    upper_frame = ds.isel(record=0)
    lower_frame = ds.isel(record=23)

    figure = pyplot.figure(figsize=(7, 10), layout='constrained')
    figure.suptitle("Sea surface height in the Timor Sea")
    upper_axes, lower_axes = figure.subplots(2, 1, subplot_kw=dict(projection=ds.ems.data_crs))

    upper_artist = ds.ems.make_artist(
        upper_axes, upper_frame['eta'], clim=(-3, 3), cmap='BrBG', add_colorbar=False)
    lower_artist = ds.ems.make_artist(
        lower_axes, lower_frame['eta'], clim=(-3, 3), cmap='BrBG', add_colorbar=False)

    # This roughly encompases the Timor Sea
    extent = (124.38, 135.15, -17.0, -8.0)

    add_coast(upper_axes)
    upper_time = datetime_from_np_time(upper_frame['t'].values)
    upper_axes.set_title(upper_time.strftime("%Y-%m-%d %H:%M +10:00"))
    upper_axes.set_extent(extent)

    add_coast(lower_axes)
    lower_time = datetime_from_np_time(lower_frame['t'].values)
    lower_axes.set_title(lower_time.strftime("%Y-%m-%d %H:%M +10:00"))
    lower_axes.set_extent(extent)

    figure.colorbar(
        lower_artist, ax=[upper_axes, lower_axes],
        location='right', fraction=0.05, label='meters')

    pyplot.show()


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

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


.. _sphx_glr_download_examples_plot-two-subplots.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: plot-two-subplots.ipynb <plot-two-subplots.ipynb>`

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

      :download:`Download Python source code: plot-two-subplots.py <plot-two-subplots.py>`

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

      :download:`Download zipped: plot-two-subplots.zip <plot-two-subplots.zip>`


.. only:: html

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

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