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]