Spectrogram

plot 05 specgram

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

Fs = 2000.0
t = np.arange(0, 3, 1 / Fs)
# a linear chirp sweeping 50 -> 500 Hz, so the band rises across the spectrogram
x = np.sin(2 * np.pi * (50 * t + (450 / (2 * 3)) * t ** 2))

fig, ax = plotpress.subplots()
m, freqs, times, im = ax.specgram(x, NFFT=256, Fs=Fs, noverlap=200, cmap="magma")
ax.set_title("specgram"); fig.colorbar(im, ax=ax)

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

Gallery generated by Sphinx-Gallery