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

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

.. _sphx_glr_gallery_lines_bars_and_markers_xcorr_acorr_demo.py:


===========================
Cross- and auto-correlation
===========================

Example use of cross-correlation (`~.Axes.xcorr`) and auto-correlation
(`~.Axes.acorr`) plots.

.. GENERATED FROM PYTHON SOURCE LINES 9-28

.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np

    # Fixing random state for reproducibility
    np.random.seed(19680801)


    x, y = np.random.randn(2, 100)
    fig, [ax1, ax2] = plt.subplots(2, 1, sharex=True)
    ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
    ax1.grid(True)
    ax1.set_title('Cross-correlation (xcorr)')

    ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
    ax2.grid(True)
    ax2.set_title('Auto-correlation (acorr)')

    plt.show()




.. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_xcorr_acorr_demo_001.png
   :alt: Cross-correlation (xcorr), Auto-correlation (acorr)
   :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_xcorr_acorr_demo_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_xcorr_acorr_demo_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 29-41

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.axes.Axes.acorr` / `matplotlib.pyplot.acorr`
   - `matplotlib.axes.Axes.xcorr` / `matplotlib.pyplot.xcorr`

.. tags::

   domain: statistics
   level: beginner


.. _sphx_glr_download_gallery_lines_bars_and_markers_xcorr_acorr_demo.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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