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

Class _Edge_integer

lib/matplotlib/ticker.py:2063–2108  ·  view source on GitHub ↗

Helper for `.MaxNLocator`, `.MultipleLocator`, etc. Take floating-point precision limitations into account when calculating tick locations as integer multiples of a step.

Source from the content-addressed store, hash-verified

2061
2062
2063class _Edge_integer:
2064 """
2065 Helper for `.MaxNLocator`, `.MultipleLocator`, etc.
2066
2067 Take floating-point precision limitations into account when calculating
2068 tick locations as integer multiples of a step.
2069 """
2070
2071 def __init__(self, step, offset):
2072 """
2073 Parameters
2074 ----------
2075 step : float > 0
2076 Interval between ticks.
2077 offset : float
2078 Offset subtracted from the data limits prior to calculating tick
2079 locations.
2080 """
2081 if step <= 0:
2082 raise ValueError("'step' must be positive")
2083 self.step = step
2084 self._offset = abs(offset)
2085
2086 def closeto(self, ms, edge):
2087 # Allow more slop when the offset is large compared to the step.
2088 if self._offset > 0:
2089 digits = np.log10(self._offset / self.step)
2090 tol = max(1e-10, 10 ** (digits - 12))
2091 tol = min(0.4999, tol)
2092 else:
2093 tol = 1e-10
2094 return abs(ms - edge) < tol
2095
2096 def le(self, x):
2097 """Return the largest n: n*step <= x."""
2098 d, m = divmod(x, self.step)
2099 if self.closeto(m / self.step, 1):
2100 return d + 1
2101 return d
2102
2103 def ge(self, x):
2104 """Return the smallest n: n*step >= x."""
2105 d, m = divmod(x, self.step)
2106 if self.closeto(m / self.step, 0):
2107 return d
2108 return d + 1
2109
2110
2111class MaxNLocator(Locator):

Callers 3

__init__Method · 0.85
set_paramsMethod · 0.85
_raw_ticksMethod · 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…