diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index c11f1b214bb7..aeeb92dec9ed 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -827,14 +827,21 @@ class LogFormatter(Formatter): """ Format values for log axis. """ - def __init__(self, base=10.0, labelOnlyBase=True): + def __init__(self, base=10.0, labelOnlyBase=False): """ `base` is used to locate the decade tick, which will be the only one to be labeled if `labelOnlyBase` is ``True``. + + Parameters + ---------- + base : float, optional, default: 10. + base of the logarithm. + + labelOnlyBase : bool, optional, default: False + whether to only label decades ticks. """ self._base = base + 0.0 self.labelOnlyBase = labelOnlyBase - self.sublabel = [1, ] def base(self, base): """ @@ -882,14 +889,6 @@ def set_locs(self, locs): vmax = math.log(vmax) / math.log(b) numdec = abs(vmax - vmin) - if numdec > 3: - # Label only bases - self.sublabel = set((1,)) - else: - # Add labels between bases at log-spaced coefficients - c = np.logspace(0, 1, (4 - int(numdec)) + 1, base=b) - self.sublabel = set(np.round(c)) - def __call__(self, x, pos=None): """ Return the format for tick val `x` at position `pos`. @@ -904,19 +903,16 @@ def __call__(self, x, pos=None): isDecade = is_close_to_int(fx) exponent = np.round(fx) if isDecade else np.floor(fx) coeff = np.round(x / b ** exponent) - if coeff in self.sublabel: - if not isDecade and self.labelOnlyBase: - return '' - elif x > 10000: - s = '%1.0e' % x - elif x < 1: - s = '%1.0e' % x - else: - s = self.pprint_val(x, self.d) - if sign == -1: - s = '-%s' % s + if not isDecade and self.labelOnlyBase: + return '' + elif x > 10000: + s = '%1.0e' % x + elif x < 1: + s = '%1.0e' % x else: - s = '' + s = self.pprint_val(x, self.d) + if sign == -1: + s = '-%s' % s return self.fix_minus(s) @@ -1043,22 +1039,19 @@ def __call__(self, x, pos=None): else: base = '%s' % b - if coeff in self.sublabel: - if not is_decade and self.labelOnlyBase: - return '' - elif not is_decade: - return self._non_decade_format(sign_string, base, fx, usetex) - else: - if usetex: - return (r'$%s%s^{%d}$') % (sign_string, - base, - nearest_long(fx)) - else: - return ('$%s$' % _mathdefault( - '%s%s^{%d}' % - (sign_string, base, nearest_long(fx)))) - else: + if not is_decade and self.labelOnlyBase: return '' + elif not is_decade: + return self._non_decade_format(sign_string, base, fx, usetex) + else: + if usetex: + return (r'$%s%s^{%d}$') % (sign_string, + base, + nearest_long(fx)) + else: + return ('$%s$' % _mathdefault( + '%s%s^{%d}' % + (sign_string, base, nearest_long(fx)))) class LogFormatterSciNotation(LogFormatterMathtext):