sample.plots module¶
Plot functions for helping visualization
This module requires extra dependencies, which you can install with
pip install lim-sample[plots]
- sample.plots.beatsdrop_comparison(model: SAMPLE, beatsdrops: Dict[str, BeatRegression], x: array, track_i: int = 0, fs: Optional[float] = None, transpose: bool = False, signal_hilbert_am: Union[bool, int] = False, warnings_ignore: bool = True, axs: Optional[Sequence[Axes]] = None, fig: Optional[Figure] = None)¶
Compare beat regression models
- Parameters:
model (SAMPLE) – Fitted
sample.sample.SAMPLE
instancebeatsdrops (dict) – Dictionary of
sample.beatsdrop.regression.BeatRegression
valuesx (array) – Original signal
track_i (int) – Index of the (beating) track of interest
fs (float) – Sampling frequency. If unspecified, it will be inferred by the
model
transpose (bool) – Swap small multiples rows and columns
signal_hilbert_am (bool or int) – If
True
, then plot the Hilbert envelope of the signal, instead of the signal. If anint
, then subsample the envelope by this factorwarnings_ignore (bool) – if
True
(default), then ignore warnings while fitting beat regression modelsaxs (sequence of axes) – Axes onto which to plot. If unspecified, they will be defined on
fig
fig (figure) – Figure onto which to put axes. If unspecified, the current figure will be used
- Returns:
Figure and axes for the plot
- Return type:
figure, axes
- sample.plots.resynthesis(x: ~numpy.ndarray, models: ~typing.Optional[~typing.Dict[str, ~sample.sample.SAMPLE]] = None, fs: ~typing.Optional[float] = None, original: bool = True, original_k: str = 'Original', axs: ~typing.Optional[~typing.Sequence[~matplotlib.axes._axes.Axes]] = None, fig: ~typing.Optional[~matplotlib.figure.Figure] = None, foreach: ~typing.Optional[~typing.Callable[[int, str, ~numpy.ndarray], ~typing.Any]] = None, wav_kws: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, tf_kws: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, tf_fun: ~typing.Callable[[~numpy.ndarray, float], ~typing.Tuple[~typing.Tuple[float, float], ~numpy.ndarray]] = <function _stft4resynthesis.<locals>._stft4resynthesis_>, db_floor: float = -90, **kwargs)¶
Plot a signal and its resynthesis, using different models
- Parameters:
x (array) – Original signal
models (dict) – Dictionary of
sample.sample.SAMPLE
valuesfs (float) – Sampling frequency. If unspecified, it will be inferred by the
models
original (bool) – If
True
(default), also plot original signalsoriginal_k (str) – Label for original signal
axs (sequence of axes) – Axes onto which to plot. If unspecified, they will be defined on
fig
fig (figure) – Figure onto which to put axes. If unspecified, the current figure will be used
foreach (callable) – Function to be called for every model. It should take three inputs: the model index, the model label and the audio signal
wav_kws (dict) – Additional keyword arguments for wave plot (
matplotlib.pyplot.plot()
)tf_kws (dict) – Additional keyword arguments for time-frequency plot (
sample.plots.tf_plot()
)tf_fun (callable) – Function for getting a time-frequency representation from a signal. It should take an audio array as a positional argument and the sampling frequency
fs
as a keyword argument. It should return the frequency limits of the representation and the time-frequency matrixdb_floor (float) – Lower threshold for tf amplitude values, in dB. If
None
, the values will not be converted in dB**kwargs – Keyword arguments for
matplotlib.figure.Figure.subplots()
- Returns:
Figure and list of axes for the plot
- Return type:
figure, axes
- sample.plots.sine_tracking_2d(s: Union[SinusoidalModel, SAMPLE], ax=None, **kwargs)¶
Plot sinusoidal tracks detected by the model on two axes, one for frequency and one for magnitude
- Parameters:
m (sample.sms.sm.SinusoidalModel) – Trained sinusoidal model (or SAMPLE model)
ax – Axes list (optional)
**kwargs – Keyword arguments for
matplotlib.pyplot.plot()
- Returns:
The axes list
- sample.plots.sine_tracking_3d(s: Union[SinusoidalModel, SAMPLE], ax=None)¶
Plot sinusoidal tracks detected by the model on one 3D axis
- Parameters:
m (sample.sms.sm.SinusoidalModel) – Trained sinusoidal model (or SAMPLE model)
ax – 3D axis (optional)
- Returns:
The 3D axis
- sample.plots.tf_plot(tf, tlim: Tuple[float, float] = (0, 1), flim: Tuple[float, float] = (0, 1), xlim: Optional[Tuple[float, float]] = None, ylim: Optional[Tuple[float, float]] = None, ax: Optional[Axes] = None, aspect_ratio: float = 1.3333333333333333, width: float = 8, **kwargs)¶
Plot a time-frequency matrix
- Parameters:
tf (matrix) – Time-frequency matrix
tlim (float, float) – Extrema for time axis of matrix
flim (float, float) – Extrema for frequency axis of matrix
xlim (float, float) – Extrema for time axis of plot
ylim (float, float) – Extrema for frequency axis of plot
ax (Axes) – Axes onto which to plot the matrix
aspect_ratio (float) – Aspect ratio for image
width (float) – Width for figure size
**kwargs – Keyword arguments for
imhsow()
- Returns:
Axes where the matrix has been plotted
- Return type:
Axes