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

.. only:: html

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

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

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

.. _sphx_glr_gallery_basic.py:


Plotting a sine
===============

An introductory example: a Matplotlib figure, some narrative between the code
blocks, and mathematics rendered with MathJax.

A gallery script starts with a triple-quoted docstring written in
reStructuredText, whose first line is the title of the example. Code and text
blocks follow it; a line beginning with ``# %%`` starts a new block, and a
comment block after it is rendered as prose rather than as code.

Mathematics is written as it is anywhere else in the documentation. This
example plots

.. math::

   x \rightarrow \sin(x)

where :math:`\sin` is evaluated at every point of :math:`x`. Escape the
backslashes when the mathematics is inside a plain docstring, or make the
docstring raw.

.. GENERATED FROM PYTHON SOURCE LINES 24-43

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    try:
        import mplstyle_reslumen  # noqa: F401

        plt.style.use("reslumen")
    except ImportError:
        pass

    x = np.linspace(0, 2 * np.pi, 100)
    y = np.sin(x)

    plt.plot(x, y)
    plt.xlabel(r"$x$")
    plt.ylabel(r"$\sin(x)$")
    plt.show()




.. image-sg:: /gallery/images/sphx_glr_basic_001.png
   :alt: basic
   :srcset: /gallery/images/sphx_glr_basic_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 44-47

Text blocks and code blocks alternate, so the narrative can explain what the
code below it is about to do. Output printed by a block is captured and shown
under it:

.. GENERATED FROM PYTHON SOURCE LINES 47-50

.. code-block:: Python


    print("This example shows a sine plot.")





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

 .. code-block:: none

    This example shows a sine plot.




.. GENERATED FROM PYTHON SOURCE LINES 51-61

Cross-referencing
-----------------

Every example gets a label of its own, so one example can link to another
with an ordinary reference — see :ref:`sphx_glr_gallery_thumbnail.py` for the
example that chooses its own thumbnail.

.. note::

   Directives work here exactly as they do on a hand-written page.


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

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


.. _sphx_glr_download_gallery_basic.py:

.. only:: html

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

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

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

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

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

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

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