maad.util.plot1d

maad.util.plot1d(x, y, ax=None, **kwargs)[source]

Plot the waveform or spectrum of an audio signal.

Parameters:
x1d ndarray of integer

Vector containing the abscissa values (horizontal axis)

y1d ndarray of scalar

Vector containing the ordinate values (vertical axis)

axaxis, optional, default is None

Draw the signal on this specific axis. Allow multiple plots on the same axis.

kwargs, optional
  • figsizetuple of integers, optional, default: (4,10)

    width, height in inches.

  • facecolormatplotlib color, optional, default: ‘w’ (white)

    the background color.

  • edgecolormatplotlib color, optional, default: ‘k’ (black)

    the border color.

  • colormatplotlib color, optional, default: ‘k’ (black)

    the line color The following color abbreviations are supported: ========== ======== character color ========== ======== ‘b’ blue ‘g’ green ‘r’ red ‘c’ cyan ‘m’ magenta ‘y’ yellow ‘k’ black ‘w’ white ========== ======== In addition, you can specify colors in many ways, including RGB tuples (0.2,1,0.5). See matplotlib color

  • linewidthscalar, optional, default: 0.5

    width in pixels

  • figtitle: string, optional, default: ‘Audiogram’

    Title of the plot

  • xlabelstring, optional, default‘Time [s]’

    label of the horizontal axis

  • ylabelstring, optional, default‘Amplitude [AU]’

    label of the vertical axis

  • legendstring, optional, defaultNone

    Legend for the plot

  • nowboolean, optional, defaultTrue

    if True, display now. Cannot display multiple plots. To display mutliple plots, set now=False until the last call for the last plot

…and more, see matplotlib

Returns:
figFigure

The Figure instance

axAxis

The Axis instance

Examples

>>> import numpy as np    
>>> s, fs = maad.sound.load('../data/cold_forest_daylight.wav') 

Plot the audiogram

>>> tn = np.arange(0,len(s))/fs
>>> fig, ax = maad.util.plot1d(tn,s)
>>> Sxx_power,tn,fn,_ = maad.sound.spectrogram(s,fs)

Convert spectrogram into dB SPL

>>> Lxx = maad.spl.power2dBSPL(Sxx_power, gain=42) 

Plot the spectrum at t = 7s

>>> index = maad.util.nearest_idx(tn,7)
>>> fig_kwargs = {'figtitle':'Spectrum (PSD)',
                'xlabel':'Frequency [Hz]',
                'ylabel':'Power [dB]',
                'linewidth': 0.5
                }
>>> fig, ax = maad.util.plot1d(fn, Lxx[:,index], **fig_kwargs)