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.
See also
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()
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()
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()
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
_locsaxisunitlag