Caution

You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.1.

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 physical unit for axis labels and ticks. Either equal to s (seconds) or ms (milliseconds) or None (default). If set to None, the resulting TimeFormatter object adapts its string representation to the duration of the underlying time range: hh:mm:ss above 3600 seconds; mm:ss between 60 and 3600 seconds; and ss below 60 seconds.

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')

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)')

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')
../_images/librosa-display-TimeFormatter-1_00.png
../_images/librosa-display-TimeFormatter-1_01.png
../_images/librosa-display-TimeFormatter-1_02.png
__init__(lag=False, unit=None)[source]

Methods

__init__([lag, unit])

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. This is a helper method to perform such a replacement when it is enabled via :rc:`axes.unicode_minus`.

format_data(value)

Return the full string representation of the value with the position unspecified.

format_data_short(value)

Return a short string version of the tick value.

format_ticks(values)

Return the tick labels for all the ticks at once.

get_offset()

set_axis(axis)

set_locs(locs)

Set the locations of the ticks.

Attributes

axis

locs