maad.util.plot2d
- maad.util.plot2d(im, ax=None, colorbar=True, **kwargs)[source]
Display the spectrogram of an audio signal.
The spectrogram should be previously computed using the function
maad.sound.spectrogram
.- Parameters:
- im2D numpy array
Image or Spectrogram
- axaxis, optional, default is None
Draw the image on this specific axis. Allow multiple plots on the same figure.
- kwargs, optional
- figsizetuple of integers, optional, default: (4,13)
width, height in inches.
- titlestring, optional, default‘Spectrogram’
title of the figure
- xlabelstring, optional, default‘Time [s]’
label of the horizontal axis
- ylabelstring, optional, default‘Frequency [Hz]’
label of the vertical axis
- xtickstuple of ndarrays, optional, defaultnone
ticks : array_like => A list of positions at which ticks should be placed. You can pass an empty list to disable yticks.
labels : array_like, optional => A list of explicit labels to place at the given locs.
- ytickstuple of ndarrays, optional, defaultnone
ticks : array_like => A list of positions at which ticks should be placed. You can pass an empty list to disable yticks.
labels : array_like, optional => A list of explicit labels to place at the given locs.
- cmapstring or Colormap object, optional, default is ‘gray’
See https://matplotlib.org/examples/color/colormaps_reference.html in order to get all the existing colormaps examples: ‘hsv’, ‘hot’, ‘bone’, ‘tab20c’, ‘jet’, ‘seismic’, ‘viridis’…
- vmin, vmaxscalar, optional, default: None
vmin and vmax are used in conjunction with norm to normalize luminance data. Note if you pass a norm instance, your settings for vmin and vmax will be ignored.
- extentlist of scalars [left, right, bottom, top], optional, default: None
The location, in data-coordinates, of the lower-left and upper-right corners. If None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices.
- nowboolean, optional, defaultTrue
if True, display now. Cannot display multiple images. To display mutliple images, set now=False until the last call for the last image
- interpolationlist of string [None, ‘none’, ‘nearest’, ‘bilinear’,
‘bicubic’, ‘spline16’,’spline36’, ‘hanning’, ‘hamming’, ‘hermite’, ‘kaiser’, ‘quadric’,’catrom’, ‘gaussian’, ‘bessel’, ‘mitchell’, ‘sinc’, ‘lanczos’], optional, default : None
… and more, see matplotlib
- Returns:
- figFigure
The Figure instance
- axAxis
The Axis instance
Examples
>>> w, fs = maad.sound.load('../data/cold_forest_daylight.wav') >>> Sxx_power,tn,fn,_ = maad.sound.spectrogram(w,fs) >>> Lxx = maad.spl.power2dBSPL(Sxx_power, gain=42) # convert into dB SPL >>> fig_kwargs = {'vmax': Lxx.max(), 'vmin':0, 'extent':(tn[0], tn[-1], fn[0], fn[-1]), 'title':'Power spectrogram density (PSD) in dB SPL', 'xlabel':'Time [s]', 'ylabel':'Frequency [Hz]', } >>> fig, ax = maad.util.plot2d(Lxx,interpolation=None,**fig_kwargs)