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

Method _compute_offset

lib/matplotlib/ticker.py:804–841  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

802 self._set_format()
803
804 def _compute_offset(self):
805 locs = self._locs
806 # Restrict to visible ticks.
807 vmin, vmax = sorted(self.axis.get_view_interval())
808 locs = np.asarray(locs)
809 locs = locs[(vmin <= locs) & (locs <= vmax)]
810 if not len(locs):
811 self.offset = 0
812 return
813 lmin, lmax = locs.min(), locs.max()
814 # Only use offset if there are at least two ticks and every tick has
815 # the same sign.
816 if lmin == lmax or lmin <= 0 <= lmax:
817 self.offset = 0
818 return
819 # min, max comparing absolute values (we want division to round towards
820 # zero so we work on absolute values).
821 abs_min, abs_max = sorted([abs(float(lmin)), abs(float(lmax))])
822 sign = math.copysign(1, lmin)
823 # What is the smallest power of ten such that abs_min and abs_max are
824 # equal up to that precision?
825 # Note: Internally using oom instead of 10 ** oom avoids some numerical
826 # accuracy issues.
827 oom_max = np.ceil(math.log10(abs_max))
828 oom = 1 + next(oom for oom in itertools.count(oom_max, -1)
829 if abs_min // 10 ** oom != abs_max // 10 ** oom)
830 if (abs_max - abs_min) / 10 ** oom <= 1e-2:
831 # Handle the case of straddling a multiple of a large power of ten
832 # (relative to the span).
833 # What is the smallest power of ten such that abs_min and abs_max
834 # are no more than 1 apart at that precision?
835 oom = 1 + next(oom for oom in itertools.count(oom_max, -1)
836 if abs_max // 10 ** oom - abs_min // 10 ** oom > 1)
837 # Only use offset if it saves at least _offset_threshold digits.
838 n = self._offset_threshold - 1
839 self.offset = (sign * (abs_max // 10 ** oom) * 10 ** oom
840 if abs_max // 10 ** oom >= 10**n
841 else 0)
842
843 def _set_order_of_magnitude(self):
844 # if scientific notation is to be used, find the appropriate exponent

Callers 2

set_locsMethod · 0.95
set_locsMethod · 0.80

Calls 4

minMethod · 0.80
maxMethod · 0.80
countMethod · 0.80
get_view_intervalMethod · 0.45

Tested by

no test coverage detected