librosa.display.waveloop#
- librosa.display.waveloop(y, *, sr=22050, duration=None, r_range=(0.5, 1.0), method='waveshow', offset=0.0, peak_norm=True, time_axis='time', theta_offset=1.5707963267948966, direction='clockwise', decorate=True, ax=None, **kwargs)[source]#
Visualize a waveform as a circular loop in polar coordinates.
This function maps a time-domain signal onto a polar projection, wrapping time from
0todurationcontinuously around the circle from0to2π.- Parameters:
- ynp.ndarray [shape=(n,) or (2,n)]
audio time series (mono or stereo).
- srnumber > 0 [scalar]
sampling rate of
y(samples per second).- durationfloat > 0 or None
The finite, strictly positive time extent in seconds mapped to one full revolution (
[0, 2π)). IfNone, defaults to the signal durationlibrosa.get_duration(y=y, sr=sr). The signal duration cannot exceedduration; multiple cycles are not supported.- r_rangetuple of (float, float)
The radial bounds
(r_min, r_max)for the waveform display, where0 <= r_min < r_max. Amplitudes in[-1, 1]are mapped linearly into this interval.- method{‘waveshow’, ‘wavebars’}
Visualization method:
- offsetfloat
Start time (in seconds) of
ywithin the[0, duration)loop (matchingwaveshowandwavebars). Loop ticks always start at0(positioned attheta_offset); settingoffsetshifts the waveform around the circle in seconds (wrapping smoothly across0whenoffset + sig_dur > duration), which is useful for placing a shorter clip partway through a loop or time-aligning concentric tracks withdecorate=False.- peak_normbool
If
True(default), normalizesyby its peak amplitude (y / max(|y|)) before mapping intor_range, preventing clipping or negative-radius origin crossings.- time_axisstr, int, Sequence[float], np.ndarray, or None
Display style of the time axis around the circle. Accepted values are:
‘time’ (default) : Formatted timestamps (adaptive unit via
TimeFormatter).‘s’, ‘ms’, ‘m’, ‘h’ : Formatted timestamps using the specified unit.
int : Number of equal subdivisions (e.g. 4, 8, 12, 16, 24, 32).
Sequence[float] or np.ndarray : Explicit timestamp locations in seconds.
None, ‘none’, or ‘off’ : Ticks and labels are hidden.
- theta_offsetfloat
Visual orientation (in radians) of
t = 0on the polar axes whendecorate=True. Default isπ / 2(12 o’clock / top); use0.0for 3 o’clock.- direction{‘clockwise’, ‘counterclockwise’, -1, 1}
Direction of time rotation around the circle. Default is ‘clockwise’.
- decoratebool
Whether to style the polar axes (setting theta direction, theta offset, angular time ticks via
time_axis, clearing radial ticks, and settingymargin(0)). Default isTrue. Set toFalseto preserve custom axes settings and ticks when using a pre-configured polar projection.- axmatplotlib.axes.Axes or None
Target axes to plot on. If a rectilinear axes is provided, it will be converted in-place to polar projection if it does not already contain artists. In-place conversion preserves subplot geometry, position,
label, and titles (left,center,right), uncouples any shared Cartesian axes, and resets other rectilinear axes styling (such as facecolor, grid, or axis labels). IfNone, a new polar axes or the current axes will be used.- **kwargs
Additional keyword arguments forwarded to the plotting function selected by method.
If method=’waveshow’, these must be keyword arguments supported by
librosa.display.waveshow(for example, max_points).If method=’wavebars’, these must be keyword arguments supported by
librosa.display.wavebars(for example, n_bars, gap_ratio, rounding_ratio, invert, and invert_color).Keyword arguments for one method are not valid when using the other.
- Returns:
- Raises:
- ParameterTypeError
If
axis notNoneand not amatplotlib.axes.Axesinstance.- ParameterValueError
If
yis empty. Ifaxhas a non-rectilinear projection (such as'3d'), or is rectilinear and already contains artists. Ifdurationis non-finite, boolean,<= 0, or less than the signal duration. Ifoffsetortheta_offsetis non-finite or boolean. Ifr_rangeis invalid or does not satisfy0 <= r_min < r_max. Ifmethod,direction, ortime_axisis not recognized. Iftranspose=True,transform, oraxisis passed inkwargs.
Examples
Plot a synthesized audio loop in polar coordinates:
>>> import matplotlib.pyplot as plt >>> y, sr = librosa.loadx("choice") >>> fig, ax = plt.subplots() >>> librosa.display.waveloop(y, sr=sr, ax=ax) >>> plt.show()
Place a shorter clip starting 1 second into a 6-second loop and align a second concentric track in seconds:
>>> fig, ax = plt.subplots(subplot_kw={"projection": "polar"}) >>> librosa.display.waveloop( ... y[: 2 * sr], sr=sr, duration=6.0, offset=1.0, r_range=(0.6, 1.0), ax=ax ... ) >>> librosa.display.waveloop( ... y[: 2 * sr], ... sr=sr, ... duration=6.0, ... offset=3.0, ... r_range=(0.2, 0.5), ... method="wavebars", ... decorate=False, ... ax=ax, ... ) >>> plt.show()