Skip to content

[WIP] Proposed improvement in default log formatting #4730

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
8 changes: 5 additions & 3 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ def pprint_val(self, x, d):
return s


SPECIAL_LOG = set((0, 0.1, 1, 10))

class LogFormatterExponent(LogFormatter):
"""
Format values for log axis; using ``exponent = log_base(value)``
Expand Down Expand Up @@ -776,11 +778,11 @@ def __call__(self, x, pos=None):
usetex = rcParams['text.usetex']

# only label the decades
if x == 0:
if x in SPECIAL_LOG:
if usetex:
return '$0$'
return '${0:g}$'.format(x)
else:
return '$\mathdefault{0}$'
return '$\mathdefault{{{0:g}}}$'.format(x)

fx = math.log(abs(x)) / math.log(b)
is_decade = is_close_to_int(fx)
Expand Down