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

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

.. _sphx_glr_gallery_showcase_integral.py:


==================================
Integral as the area under a curve
==================================

Although this is a simple example, it demonstrates some important tweaks:

* A simple line plot with custom color and line width.
* A shaded region created using a Polygon patch.
* A text label with mathtext rendering.
* figtext calls to label the x- and y-axes.
* Use of axis spines to hide the top and right spines.
* Custom tick placement and labels.

.. GENERATED FROM PYTHON SOURCE LINES 15-51



.. image-sg:: /gallery/showcase/images/sphx_glr_integral_001.png
   :alt: integral
   :srcset: /gallery/showcase/images/sphx_glr_integral_001.png, /gallery/showcase/images/sphx_glr_integral_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    from matplotlib.patches import Polygon


    def func(x):
        return (x - 3) * (x - 5) * (x - 7) + 85


    a, b = 2, 9  # integral limits
    x = np.linspace(0, 10)
    y = func(x)

    fig, ax = plt.subplots()
    ax.plot(x, y, 'r', linewidth=2)
    ax.set_ylim(bottom=0)

    # Make the shaded region
    ix = np.linspace(a, b)
    iy = func(ix)
    verts = [(a, 0), *zip(ix, iy), (b, 0)]
    poly = Polygon(verts, facecolor='0.9', edgecolor='0.5')
    ax.add_patch(poly)

    ax.text(0.5 * (a + b), 30, r"$\int_a^b f(x)\mathrm{d}x$",
            horizontalalignment='center', fontsize=20)

    fig.text(0.9, 0.05, '$x$')
    fig.text(0.1, 0.9, '$y$')

    ax.spines[['top', 'right']].set_visible(False)
    ax.set_xticks([a, b], labels=['$a$', '$b$'])
    ax.set_yticks([])

    plt.show()


.. _sphx_glr_download_gallery_showcase_integral.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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