diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 78d693adeaad..4c4cdb3c4498 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -1,8 +1,6 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) -import six - from numpy.testing import assert_almost_equal import numpy as np import pytest @@ -305,6 +303,7 @@ def test_LogFormatterExponent_blank(): def test_LogFormatterSciNotation(): test_cases = { 10: ( + (-1, '${-10^{0}}$'), (1e-05, '${10^{-5}}$'), (1, '${10^{0}}$'), (100000, '${10^{5}}$'), diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 102a7988fc21..c11f1b214bb7 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -898,14 +898,15 @@ def __call__(self, x, pos=None): if x == 0.0: return '0' sign = np.sign(x) + x = abs(x) # only label the decades - fx = math.log(abs(x)) / math.log(b) + fx = math.log(x) / math.log(b) 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: - s = '' + return '' elif x > 10000: s = '%1.0e' % x elif x < 1: @@ -1032,7 +1033,7 @@ def __call__(self, x, pos=None): fx = math.log(abs(x)) / math.log(b) is_decade = is_close_to_int(fx) exponent = np.round(fx) if is_decade else np.floor(fx) - coeff = np.round(x / b ** exponent) + coeff = np.round(abs(x) / b ** exponent) sign_string = '-' if x < 0 else ''