Note
Go to the end to download the full example code.
Cross spectral density

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(1)
Fs = 1000.0
t = np.arange(0, 4, 1 / Fs)
common = np.sin(2 * np.pi * 90 * t)
x = common + 0.5 * rng.standard_normal(t.size)
y = np.roll(common, 12) + 0.5 * rng.standard_normal(t.size) # shared 90 Hz tone
fig, ax = plotpress.subplots()
ax.csd(x, y, NFFT=512, Fs=Fs, noverlap=256, color="C3")
ax.set_title("csd")
Total running time of the script: (0 minutes 0.068 seconds)