From 2432eb8a5916da5119cb487bf9b79e1ebe6aed4e Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 17 Jul 2015 14:55:12 +0800 Subject: [PATCH] Use 0.1, 1, and 10 in log formatter instead of 10^-1, 10^0, and 10^1 --- lib/matplotlib/ticker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index c3bc178f8865..a6151b9db599 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -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)`` @@ -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)