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

.. only:: html

    .. meta::
        :keywords: codex

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

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

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

.. _sphx_glr_gallery_subplots_axes_and_figures_figure_title.py:


=============================================
Figure labels: suptitle, supxlabel, supylabel
=============================================

Each Axes can have a title (or actually three - one each with *loc* "left",
"center", and "right"), but is sometimes desirable to give a whole figure
(or `.SubFigure`) an overall title, using `.Figure.suptitle`.

We can also add figure-level x- and y-labels using `.Figure.supxlabel` and
`.Figure.supylabel`.

.. GENERATED FROM PYTHON SOURCE LINES 13-33

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.cbook import get_sample_data

    x = np.linspace(0.0, 5.0, 501)

    fig, (ax1, ax2) = plt.subplots(1, 2, layout='constrained', sharey=True)
    ax1.plot(x, np.cos(6*x) * np.exp(-x))
    ax1.set_title('damped')
    ax1.set_xlabel('time (s)')
    ax1.set_ylabel('amplitude')

    ax2.plot(x, np.cos(6*x))
    ax2.set_xlabel('time (s)')
    ax2.set_title('undamped')

    fig.suptitle('Different types of oscillations', fontsize=16)


.. GENERATED FROM PYTHON SOURCE LINES 34-36

A global x- or y-label can be set using the `.Figure.supxlabel` and
`.Figure.supylabel` methods.

.. GENERATED FROM PYTHON SOURCE LINES 36-55

.. code-block:: Python



    with get_sample_data('Stocks.csv') as file:
        stocks = np.genfromtxt(
            file, delimiter=',', names=True, dtype=None,
            converters={0: lambda x: np.datetime64(x, 'D')}, skip_header=1)

    fig, axs = plt.subplots(4, 2, figsize=(9, 5), layout='constrained',
                            sharex=True, sharey=True)
    for nn, ax in enumerate(axs.flat):
        column_name = stocks.dtype.names[1+nn]
        y = stocks[column_name]
        line, = ax.plot(stocks['Date'], y / np.nanmax(y), lw=2.5)
        ax.set_title(column_name, fontsize='small', loc='left')
    fig.supxlabel('Year')
    fig.supylabel('Stock price relative to max')

    plt.show()


.. GENERATED FROM PYTHON SOURCE LINES 56-62

.. tags::

   component: figure
   component: title
   plot-type: line
   level: beginner


.. _sphx_glr_download_gallery_subplots_axes_and_figures_figure_title.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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