librosa.display.TimeFormatter#

class librosa.display.TimeFormatter(lag=False, unit=None)[source]#

A tick formatter for time axes.

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

Parameters:
lagbool

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

unitstr or None

Abbreviation of the string representation for axis labels and ticks. List of supported units: * “h”: hour-based format (H:MM:SS) * “m”: minute-based format (M:SS) * “s”: second-based format (S.sss in scientific notation) * “ms”: millisecond-based format (s.µµµ in scientific notation) * None: adaptive to the duration of the underlying time range: similar to “h” above 3600 seconds; to “m” between 60 and 3600 seconds; to “s” between 1 and 60 seconds; and to “ms” below 1 second.

Examples

For normal time

>>> import matplotlib.pyplot as plt
>>> times = np.arange(30)
>>> values = np.random.randn(len(times))
>>> fig, ax = plt.subplots()
>>> ax.plot(times, values)
>>> ax.xaxis.set_major_formatter(librosa.display.TimeFormatter())
>>> ax.set(xlabel='Time')
>>> plt.show()
../../_images/librosa-display-TimeFormatter-1_00_00.png

Manually set the physical time unit of the x-axis to milliseconds

>>> times = np.arange(100)
>>> values = np.random.randn(len(times))
>>> fig, ax = plt.subplots()
>>> ax.plot(times, values)
>>> ax.xaxis.set_major_formatter(librosa.display.TimeFormatter(unit='ms'))
>>> ax.set(xlabel='Time (ms)')
>>> plt.show()
../../_images/librosa-display-TimeFormatter-1_01_00.png

For lag plots

>>> times = np.arange(60)
>>> values = np.random.randn(len(times))
>>> fig, ax = plt.subplots()
>>> ax.plot(times, values)
>>> ax.xaxis.set_major_formatter(librosa.display.TimeFormatter(lag=True))
>>> ax.set(xlabel='Lag')
>>> plt.show()
../../_images/librosa-display-TimeFormatter-1_02_00.png
__init__(lag=False, unit=None)[source]#

Methods

__call__(x[, pos])

Return the time format as pos

__delattr__(name, /)

Implement delattr(self, name).

__dir__(/)

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getstate__(/)

Helper for pickle.

__gt__(value, /)

Return self>value.

__hash__(/)

Return hash(self).

__init__([lag, unit])

__init_subclass__

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(*args, **kwargs)

__reduce__(/)

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__(/)

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__(/)

Size of object in memory, in bytes.

__str__(/)

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

Attributes

__annotations__

__dict__

__doc__

__module__

__weakref__

list of weak references to the object

_locs

axis

unit

lag