matplotlib.mlab¶Numerical python functions written for compatibility with MATLAB
commands with the same names. Most numerical python functions can be found in
the numpy and scipy libraries. What remains here is code for performing
spectral computations.
coherecsddetrendpsdspecgramcomplex_spectrummagnitude_spectrumangle_spectrumphase_spectrumdetrend_meandetrend_lineardetrend_nonestride_windowsstride_repeatapply_windowmatplotlib.mlab.GaussianKDE(dataset, bw_method=None)[source]¶Bases: object
Representation of a kernel-density estimate using Gaussian kernels.
| Parameters: | dataset : array_like
bw_method : str, scalar or callable, optional
|
|---|
Attributes
| dataset | (ndarray) The dataset with which gaussian_kde was initialized. |
| dim | (int) Number of dimensions. |
| num_dp | (int) Number of datapoints. |
| factor | (float) The bandwidth factor, obtained from kde.covariance_factor, with which the covariance matrix is multiplied. |
| covariance | (ndarray) The covariance matrix of dataset, scaled by the calculated bandwidth (kde.factor). |
| inv_cov | (ndarray) The inverse of covariance. |
Methods
| kde.evaluate(points) | (ndarray) Evaluate the estimated pdf on a provided set of points. |
| kde(points) | (ndarray) Same as kde.evaluate(points) |
covariance_factor()¶evaluate(points)[source]¶Evaluate the estimated pdf on a set of points.
| Parameters: | points : (# of dimensions, # of points)-array
|
|---|---|
| Returns: | values : (# of points,)-array
|
| Raises: | ValueError : if the dimensionality of the input points is different
|
matplotlib.mlab.angle_spectrum(x, Fs=None, window=None, pad_to=None, sides=None)[source]¶Compute the angle of the frequency spectrum (wrapped phase spectrum) of x. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
| Parameters: | x : 1-D array or sequence
Fs : scalar
window : callable or ndarray
sides : {'default', 'onesided', 'twosided'}
pad_to : int
|
|---|---|
| Returns: | spectrum : 1-D array
freqs : 1-D array
|
See also
complex_spectrumcomplex_spectrum.magnitude_spectrumphase_spectrumspecgrammatplotlib.mlab.apply_window(x, window, axis=0, return_window=None)[source]¶Apply the given window to the given 1D or 2D array along the given axis.
| Parameters: | x : 1D or 2D array or sequence
window : function or array.
axis : integer
return_window : bool
|
|---|
matplotlib.mlab.cohere(x, y, NFFT=256, Fs=2, detrend=<function detrend_none>, window=<function window_hanning>, noverlap=0, pad_to=None, sides='default', scale_by_freq=None)[source]¶The coherence between x and y. Coherence is the normalized cross spectral density:
| Parameters: | x, y
Fs : scalar
window : callable or ndarray
sides : {'default', 'onesided', 'twosided'}
pad_to : int
NFFT : int
detrend : {'none', 'mean', 'linear'} or callable, default 'none'
scale_by_freq : bool, optional
noverlap : integer
|
|---|---|
| Returns: | The return value is the tuple (Cxy, f), where f are the frequencies of the coherence vector. For cohere, scaling the individual densities by the sampling frequency has no effect, since the factors cancel out. |
matplotlib.mlab.complex_spectrum(x, Fs=None, window=None, pad_to=None, sides=None)[source]¶Compute the complex-valued frequency spectrum of x. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
| Parameters: | x : 1-D array or sequence
Fs : scalar
window : callable or ndarray
sides : {'default', 'onesided', 'twosided'}
pad_to : int
|
|---|---|
| Returns: | spectrum : 1-D array
freqs : 1-D array
|
See also
magnitude_spectrumangle_spectrumphase_spectrumspecgrammatplotlib.mlab.csd(x, y, NFFT=None, Fs=None, detrend=None, window=None, noverlap=None, pad_to=None, sides=None, scale_by_freq=None)[source]¶Compute the cross-spectral density.
The cross spectral density \(P_{xy}\) by Welch's average periodogram method. The vectors x and y are divided into NFFT length segments. Each segment is detrended by function detrend and windowed by function window. noverlap gives the length of the overlap between segments. The product of the direct FFTs of x and y are averaged over each segment to compute \(P_{xy}\), with a scaling to correct for power loss due to windowing.
If len(x) < NFFT or len(y) < NFFT, they will be zero padded to NFFT.
| Parameters: | x, y : 1-D arrays or sequences
Fs : scalar
window : callable or ndarray
sides : {'default', 'onesided', 'twosided'}
pad_to : int
NFFT : int
detrend : {'none', 'mean', 'linear'} or callable, default 'none'
scale_by_freq : bool, optional
noverlap : integer
|
|---|---|
| Returns: | Pxy : 1-D array
freqs : 1-D array
|
See also
psdy = x.References
Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John Wiley & Sons (1986)
matplotlib.mlab.demean(x, axis=0)[source]¶[Deprecated] Return x minus its mean along the specified axis.
| Parameters: | x : array or sequence
axis : integer
|
|---|
See also
detrend_meandemean except for the default axis.Notes
Deprecated since version 3.1.
matplotlib.mlab.detrend(x, key=None, axis=None)[source]¶Return x with its trend removed.
| Parameters: | x : array or sequence
key : [ 'default' | 'constant' | 'mean' | 'linear' | 'none'] or function
axis : integer
|
|---|
See also
detrend_meandetrend_lineardetrend_nonematplotlib.mlab.detrend_linear(y)[source]¶Return x minus best fit line; 'linear' detrending.
| Parameters: | y : 0-D or 1-D array or sequence
axis : integer
|
|---|
See also
detrend_meandetrend_nonedetrendmatplotlib.mlab.detrend_mean(x, axis=None)[source]¶Return x minus the mean(x).
| Parameters: | x : array or sequence
axis : integer
|
|---|
See also
detrend_lineardetrend_nonedetrendmatplotlib.mlab.detrend_none(x, axis=None)[source]¶Return x: no detrending.
| Parameters: | x : any object
axis : integer
|
|---|
See also
detrend_meandetrend_lineardetrendmatplotlib.mlab.magnitude_spectrum(x, Fs=None, window=None, pad_to=None, sides=None)[source]¶Compute the magnitude (absolute value) of the frequency spectrum of x. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
| Parameters: | x : 1-D array or sequence
Fs : scalar
window : callable or ndarray
sides : {'default', 'onesided', 'twosided'}
pad_to : int
|
|---|---|
| Returns: | spectrum : 1-D array
freqs : 1-D array
|
See also
psdcomplex_spectrumcomplex_spectrum.angle_spectrumphase_spectrumspecgrammatplotlib.mlab.phase_spectrum(x, Fs=None, window=None, pad_to=None, sides=None)[source]¶Compute the phase of the frequency spectrum (unwrapped angle spectrum) of x. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
| Parameters: | x : 1-D array or sequence
Fs : scalar
window : callable or ndarray
sides : {'default', 'onesided', 'twosided'}
pad_to : int
|
|---|---|
| Returns: | spectrum : 1-D array
freqs : 1-D array
|
See also
complex_spectrumcomplex_spectrum.magnitude_spectrumangle_spectrumspecgrammatplotlib.mlab.psd(x, NFFT=None, Fs=None, detrend=None, window=None, noverlap=None, pad_to=None, sides=None, scale_by_freq=None)[source]¶Compute the power spectral density.
The power spectral density \(P_{xx}\) by Welch's average periodogram method. The vector x is divided into NFFT length segments. Each segment is detrended by function detrend and windowed by function window. noverlap gives the length of the overlap between segments. The \(|\mathrm{fft}(i)|^2\) of each segment \(i\) are averaged to compute \(P_{xx}\).
If len(x) < NFFT, it will be zero padded to NFFT.
| Parameters: | x : 1-D array or sequence
Fs : scalar
window : callable or ndarray
sides : {'default', 'onesided', 'twosided'}
pad_to : int
NFFT : int
detrend : {'none', 'mean', 'linear'} or callable, default 'none'
scale_by_freq : bool, optional
noverlap : integer
|
|---|---|
| Returns: | Pxx : 1-D array
freqs : 1-D array
|
See also
specgramspecgram differs in the default overlap; in not returning the mean of the segment periodograms; and in returning the times of the segments.magnitude_spectrumcsdReferences
Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John Wiley & Sons (1986)
matplotlib.mlab.specgram(x, NFFT=None, Fs=None, detrend=None, window=None, noverlap=None, pad_to=None, sides=None, scale_by_freq=None, mode=None)[source]¶Compute a spectrogram.
Compute and plot a spectrogram of data in x. Data are split into NFFT length segments and the spectrum of each section is computed. The windowing function window is applied to each segment, and the amount of overlap of each segment is specified with noverlap.
| Parameters: | x : array_like
Fs : scalar
window : callable or ndarray
sides : {'default', 'onesided', 'twosided'}
pad_to : int
NFFT : int
detrend : {'none', 'mean', 'linear'} or callable, default 'none'
scale_by_freq : bool, optional
noverlap : int, optional
mode : str, optional
|
|---|---|
| Returns: | spectrum : array_like
freqs : array_like
t : array_like
|
See also
psdcomplex_spectrummagnitude_spectrumangle_spectrumphase_spectrumNotes
detrend and scale_by_freq only apply when mode is set to 'psd'.
matplotlib.mlab.stride_repeat(x, n, axis=0)[source]¶Repeat the values in an array in a memory-efficient manner. Array x is stacked vertically n times.
Warning
It is not safe to write to the output array. Multiple elements may point to the same piece of memory, so modifying one value may change others.
| Parameters: | x : 1D array or sequence
n : integer
axis : integer
|
|---|
References
matplotlib.mlab.stride_windows(x, n, noverlap=None, axis=0)[source]¶Get all windows of x with length n as a single array, using strides to avoid data duplication.
Warning
It is not safe to write to the output array. Multiple elements may point to the same piece of memory, so modifying one value may change others.
| Parameters: | x : 1D array or sequence
n : integer
noverlap : integer
axis : integer
|
|---|
References
stackoverflow: Rolling window for 1D arrays in Numpy? stackoverflow: Using strides for an efficient moving average filter
matplotlib.mlab.window_hanning(x)[source]¶Return x times the hanning window of len(x).
See also
window_nonematplotlib.mlab.window_none(x)[source]¶No window function; simply return x.
See also
window_hanning