librosa.display.TimeFormatter

class librosa.display.TimeFormatter(lag=False)[source]

A tick formatter for time axes.

Automatically switches between seconds, minutes:seconds, or hours:minutes:seconds.

Parameters:
lag : bool

If True, then the time axis is interpreted in lag coordinates. Anything past the mid-point will be converted to negative time.

Examples

For normal time

>>> import matplotlib.pyplot as plt
>>> times = np.arange(30)
>>> values = np.random.randn(len(times))
>>> plt.figure()
>>> ax = plt.gca()
>>> ax.plot(times, values)
>>> ax.xaxis.set_major_formatter(librosa.display.TimeFormatter())
>>> ax.set_xlabel('Time')

For lag plots

>>> times = np.arange(60)
>>> values = np.random.randn(len(times))
>>> plt.figure()
>>> ax = plt.gca()
>>> ax.plot(times, values)
>>> ax.xaxis.set_major_formatter(librosa.display.TimeFormatter(lag=True))
>>> ax.set_xlabel('Lag')

(Source code)

../_images/librosa-display-TimeFormatter-1_00.png
../_images/librosa-display-TimeFormatter-1_01.png
__init__(lag=False)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([lag]) Initialize self.
create_dummy_axis(**kwargs)
fix_minus(s) Some classes may want to replace a hyphen for minus with the proper unicode symbol (U+2212) for typographical correctness.
format_data(value) Returns the full string representation of the value with the position unspecified.
format_data_short(value) Return a short string version of the tick value.
get_offset()
set_axis(axis)
set_bounds(vmin, vmax)
set_data_interval(vmin, vmax)
set_locs(locs)
set_view_interval(vmin, vmax)

Attributes

axis
locs