From d52675fb23bf5b253383ab393bcf05fbb7c500a5 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Sun, 23 Oct 2016 11:17:26 -0700 Subject: [PATCH 1/3] FIX symlog scale now shows negative labels. The formatter returned empty strings for negative value. closes #7146 --- lib/matplotlib/tests/test_ticker.py | 3 +-- lib/matplotlib/ticker.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) 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..e1198e36795b 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -902,7 +902,7 @@ def __call__(self, x, pos=None): fx = math.log(abs(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) + coeff = np.round(abs(x) / b ** exponent) if coeff in self.sublabel: if not isDecade and self.labelOnlyBase: s = '' @@ -1032,7 +1032,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 '' From 46083bfd5503b4feab7ef02998d559dc75f52f30 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Mon, 24 Oct 2016 11:52:38 -0400 Subject: [PATCH 2/3] FIX more fixes for tickers --- lib/matplotlib/ticker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index e1198e36795b..4363454472a9 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -905,11 +905,11 @@ def __call__(self, x, pos=None): coeff = np.round(abs(x) / b ** exponent) if coeff in self.sublabel: if not isDecade and self.labelOnlyBase: - s = '' + return '' elif x > 10000: - s = '%1.0e' % x + s = '%1.0e' % abs(x) elif x < 1: - s = '%1.0e' % x + s = '%1.0e' % abs(x) else: s = self.pprint_val(x, self.d) if sign == -1: From 0199251bc5f871354171d28787962070c22e3aae Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Mon, 24 Oct 2016 15:49:16 -0400 Subject: [PATCH 3/3] FIX negative value for log formatter is now better dealt with --- lib/matplotlib/ticker.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 4363454472a9..c11f1b214bb7 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -898,18 +898,19 @@ 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(abs(x) / b ** exponent) + coeff = np.round(x / b ** exponent) if coeff in self.sublabel: if not isDecade and self.labelOnlyBase: return '' elif x > 10000: - s = '%1.0e' % abs(x) + s = '%1.0e' % x elif x < 1: - s = '%1.0e' % abs(x) + s = '%1.0e' % x else: s = self.pprint_val(x, self.d) if sign == -1: