You are reading an old version of the documentation (v2.1.1). For the latest version see https://matplotlib.org/stable/gallery/lines_bars_and_markers/xcorr_acorr_demo.html
matplotlib
Fork me on GitHub


Travis-CI:

Related Topics

This Page

Cross- and Auto-Correlation DemoΒΆ

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

../../_images/sphx_glr_xcorr_acorr_demo_001.png
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()

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

Gallery generated by Sphinx-Gallery