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

    Click :ref:`here <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 Demo
================================

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




.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_xcorr_acorr_demo_001.png
    :class: sphx-glr-single-img





.. 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.axhline(0, color='black', lw=2)

    ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
    ax2.grid(True)
    ax2.axhline(0, color='black', lw=2)

    plt.show()


.. _sphx_glr_download_gallery_lines_bars_and_markers_xcorr_acorr_demo.py:


.. only :: html

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



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
