MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / MicrosecondLocator

Class MicrosecondLocator

lib/matplotlib/dates.py:1657–1725  ·  view source on GitHub ↗

Make ticks on regular intervals of one or more microsecond(s). .. note:: By default, Matplotlib uses a floating point representation of time in days since the epoch, so plotting data with microsecond time resolution does not work well for dates that are far

Source from the content-addressed store, hash-verified

1655
1656
1657class MicrosecondLocator(DateLocator):
1658 """
1659 Make ticks on regular intervals of one or more microsecond(s).
1660
1661 .. note::
1662
1663 By default, Matplotlib uses a floating point representation of time in
1664 days since the epoch, so plotting data with
1665 microsecond time resolution does not work well for
1666 dates that are far (about 70 years) from the epoch (check with
1667 `~.dates.get_epoch`).
1668
1669 If you want sub-microsecond resolution time plots, it is strongly
1670 recommended to use floating point seconds, not datetime-like
1671 time representation.
1672
1673 If you really must use datetime.datetime() or similar and still
1674 need microsecond precision, change the time origin via
1675 `.dates.set_epoch` to something closer to the dates being plotted.
1676 See :doc:`/gallery/ticks/date_precision_and_epochs`.
1677
1678 """
1679 def __init__(self, interval=1, tz=None):
1680 """
1681 Parameters
1682 ----------
1683 interval : int, default: 1
1684 The interval between each iteration. For example, if
1685 ``interval=2``, mark every second occurrence.
1686 tz : str or `~datetime.tzinfo`, default: :rc:`timezone`
1687 Ticks timezone. If a string, *tz* is passed to `dateutil.tz`.
1688 """
1689 super().__init__(tz=tz)
1690 self._interval = interval
1691 self._wrapped_locator = ticker.MultipleLocator(interval)
1692
1693 def set_axis(self, axis):
1694 self._wrapped_locator.set_axis(axis)
1695 return super().set_axis(axis)
1696
1697 def __call__(self):
1698 # if no data have been set, this will tank with a ValueError
1699 try:
1700 dmin, dmax = self.viewlim_to_dt()
1701 except ValueError:
1702 return []
1703
1704 return self.tick_values(dmin, dmax)
1705
1706 def tick_values(self, vmin, vmax):
1707 nmin, nmax = date2num((vmin, vmax))
1708 t0 = np.floor(nmin)
1709 nmax = nmax - t0
1710 nmin = nmin - t0
1711 nmin *= MUSECONDS_PER_DAY
1712 nmax *= MUSECONDS_PER_DAY
1713
1714 ticks = self._wrapped_locator.tick_values(nmin, nmax)

Callers 1

get_locatorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…