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 0 to duration continuously around the circle from 0 to 2π.

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π)). If None, defaults to the signal duration librosa.get_duration(y=y, sr=sr). The signal duration cannot exceed duration; multiple cycles are not supported.

r_rangetuple of (float, float)

The radial bounds (r_min, r_max) for the waveform display, where 0 <= r_min < r_max. Amplitudes in [-1, 1] are mapped linearly into this interval.

method{‘waveshow’, ‘wavebars’}

Visualization method:

  • ‘waveshow’ : Continuous adaptive waveform using waveshow.

  • ‘wavebars’ : Discrete radial barcode using wavebars.

offsetfloat

Start time (in seconds) of y within the [0, duration) loop (matching waveshow and wavebars). Loop ticks always start at 0 (positioned at theta_offset); setting offset shifts the waveform around the circle in seconds (wrapping smoothly across 0 when offset + sig_dur > duration), which is useful for placing a shorter clip partway through a loop or time-aligning concentric tracks with decorate=False.

peak_normbool

If True (default), normalizes y by its peak amplitude (y / max(|y|)) before mapping into r_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 = 0 on the polar axes when decorate=True. Default is π / 2 (12 o’clock / top); use 0.0 for 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 setting ymargin(0)). Default is True. Set to False to 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). If None, 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:
librosa.display.AdaptiveWaveplot or matplotlib.collections.PatchCollection

The underlying artist constructed by waveshow or wavebars.

Raises:
ParameterTypeError

If ax is not None and not a matplotlib.axes.Axes instance.

ParameterValueError

If y is empty. If ax has a non-rectilinear projection (such as '3d'), or is rectilinear and already contains artists. If duration is non-finite, boolean, <= 0, or less than the signal duration. If offset or theta_offset is non-finite or boolean. If r_range is invalid or does not satisfy 0 <= r_min < r_max. If method, direction, or time_axis is not recognized. If transpose=True, transform, or axis is passed in kwargs.

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()
../../_images/librosa-display-waveloop-1_00_00.png

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()
../../_images/librosa-display-waveloop-1_01_00.png