Note
Go to the end to download the full example code.
Cross-correlation

Live figure — pick a tool, then zoom, pan, point-pick or annotate. Nothing is active until a tool is selected.
View this figure’s Vega export ↗ — the raw JSON spec, rendered live by a real Vega engine.
View this figure’s Vega-Lite export ↗ — the raw JSON spec(s), rendered live by a real Vega-Lite engine.
import numpy as np
import plotpress
rng = np.random.default_rng(0)
n = 400
x = rng.standard_normal(n)
y = np.roll(x, 15) + 0.4 * rng.standard_normal(n) # y lags x by 15 samples
fig, ax = plotpress.subplots()
ax.xcorr(x, y, maxlags=40, color="C2")
ax.set_title("xcorr (peak at the lag)"); ax.set_xlabel("lag")
Total running time of the script: (0 minutes 0.050 seconds)