Skip to content

Proposed change to default log scale tick formatting #5161

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

Merged
merged 9 commits into from
Aug 22, 2016
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
generalize label location for all bases
fix pep8

fix close to decade coefficients
  • Loading branch information
zblz committed Aug 2, 2016
commit a6e954d87acd83b6f96cd166b25b8cfb4f487cdc
25 changes: 13 additions & 12 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ def pprint_val(self, x, d):
s = s.rstrip('0').rstrip('.')
return s


class LogFormatterExponent(LogFormatter):
"""
Format values for log axis using ``exponent = log_base(value)``.
Expand Down Expand Up @@ -999,6 +1000,7 @@ def __call__(self, x, pos=None):
'%s%s^{%d}' %
(sign_string, base, nearest_long(fx))))


class LogFormatterSciNotation(LogFormatterMathtext):
"""
Format values following scientific notation in a logarithmic axis
Expand All @@ -1022,6 +1024,7 @@ def _non_decade_format(self, sign_string, base, fx, usetex):
return (r'$\mathdefault{%g\times%s^{%d}}$') % \
(coeff, base, exponent)


class LogitFormatter(Formatter):
"""
Probability formatter (using Math text).
Expand Down Expand Up @@ -1932,22 +1935,20 @@ def show_tick_label(self, ticklocs):
numdec = abs(vmax - vmin)

if numdec > 3:
# Label only bases
sublabel = set((1,))
elif numdec > 2:
sublabel = set((1, 3))
elif numdec > 1:
sublabel = set((1, 2, 5))
else:
sublabel = set((1, 2, 4, 7))
# Add labels between bases at log-spaced coefficients
c = np.logspace(0, 1, (4 - int(numdec)) + 1, base=b)
sublabel = set(np.round(c))

label = np.ones(ticklocs.size, dtype=np.bool)
for i, loc in enumerate(ticklocs):
exponent = math.floor(math.log(abs(loc)) / math.log(b))
coeff = loc / b ** nearest_long(exponent)
if nearest_long(coeff) not in sublabel:
label[i] = False
fx = np.log(abs(ticklocs)) / np.log(b)
exponents = np.array([np.round(x) if is_close_to_int(x)
else np.floor(x)
for x in fx])
coeffs = np.round(ticklocs / b ** exponents)

return label
return [c in sublabel for c in coeffs]

def view_limits(self, vmin, vmax):
'Try to choose the view limits intelligently'
Expand Down