{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Cross- and auto-correlation\n\nExample use of cross-correlation (`~.Axes.xcorr`) and auto-correlation\n(`~.Axes.acorr`) plots.\n\n.. redirect-from:: /gallery/lines_bars_and_markers/xcorr_acorr_demo\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n\nx, y = np.random.randn(2, 100)\nfig, [ax1, ax2] = plt.subplots(2, 1, sharex=True)\nax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)\nax1.grid(True)\nax1.set_title('Cross-correlation (xcorr)')\n\nax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)\nax2.grid(True)\nax2.set_title('Auto-correlation (acorr)')\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. admonition:: References\n\n   The use of the following functions, methods, classes and modules is shown\n   in this example:\n\n   - `matplotlib.axes.Axes.acorr` / `matplotlib.pyplot.acorr`\n   - `matplotlib.axes.Axes.xcorr` / `matplotlib.pyplot.xcorr`\n\n.. tags::\n\n   domain: statistics\n   level: beginner\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}