maad.util.plot_spectrogram

maad.util.plot_spectrogram(Sxx, extent, db_range=96, gain=0, log_scale=True, colorbar=True, interpolation='bilinear', **kwargs)[source]

Plot spectrogram represenation.

Parameters:
Sxx2d ndarray

Spectrogram computed using maad.sound.spectrogram.

extentlist of scalars [left, right, bottom, top]

Location, in data-coordinates, of the lower-left and upper-right corners.

db_rangeint or float, optional

Range of values to display the spectrogram. The default is 96.

gainint or float, optional

Gain in decibels added to the signal for display. The default is 0.

log_scalebool, optional

Logarithmic transformation of spectrogram coefficients to enhace visual representation. The default is True.

colorbarbool, optional

Plot the colorbar next to the spectrogram. The default is True.

interpolationbool, optional

Interpolate spectrogram values to enhance visual representation. The default is ‘bilinear’.

**kwargsmatplotlib figure properties

Other keyword arguments that are passed down to matplotlib.axes.

Returns:
axmatplotlib.axes

The matplotlib axes associated to plot.

See also

maad.sound.plot_spectrum, maad.util.plot_wave

Examples

Plot the spectrogram of an audio.

>>> from maad import sound, util
>>> s, fs = sound.load('../data/spinetail.wav') 
>>> Sxx, tn, fn, ext = sound.spectrogram(s,fs)
>>> util.plot_spectrogram(Sxx, ext, db_range=50, gain=30, figsize=(4,10))

Use plot_spectrogram with predifined matplotlib axes.

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(2,1, figsize=(10,6))
>>> util.plot_wave(s, fs, ax=ax[0])
>>> util.plot_spectrogram(Sxx, ext, db_range=50, gain=30, colorbar=False, ax=ax[1])

Plot a single frase of the spinetail.

>>> Sxx, tn, fn, ext = sound.spectrogram(s,fs, flims=(2000,15000), tlims=(5,8))
>>> util.plot_spectrogram(Sxx, ext, db_range=50, gain=30, figsize=(4,6))