Skip to content

[WIP] FIX log formatters now work with colorbars #7414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 30 additions & 37 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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`.
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand Down