From 177f56040a4d75c67f0bb4413e9d7c614e64c589 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Mon, 5 Sep 2016 11:26:05 -1000 Subject: [PATCH 1/2] FIX: LogLocator.set_params() was clobbering methods --- lib/matplotlib/ticker.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 4aff074e5503..2a3f16d93c79 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1757,11 +1757,13 @@ class LogLocator(Locator): Determine the tick locations for log axes """ - def __init__(self, base=10.0, subs=[1.0], numdecs=4, numticks=15): + def __init__(self, base=10.0, subs=None, numdecs=4, numticks=15): """ place ticks on the location= base**i*subs[j] """ self.base(base) + if subs is None: + subs = [1.0] self.subs(subs) # this needs to be validated > 1 with traitlets self.numticks = numticks @@ -1770,9 +1772,9 @@ def __init__(self, base=10.0, subs=[1.0], numdecs=4, numticks=15): def set_params(self, base=None, subs=None, numdecs=None, numticks=None): """Set parameters within this locator.""" if base is not None: - self.base = base + self.base(base) if subs is not None: - self.subs = subs + self.subs(subs) if numdecs is not None: self.numdecs = numdecs if numticks is not None: @@ -1782,7 +1784,7 @@ def base(self, base): """ set the base of the log scaling (major tick every base**i, i integer) """ - self._base = base + 0.0 + self._base = float(base) def subs(self, subs): """ @@ -1791,7 +1793,7 @@ def subs(self, subs): if subs is None: self._subs = None # autosub else: - self._subs = np.asarray(subs) + 0.0 + self._subs = np.asarray(subs, dtype=float) def __call__(self): 'Return the locations of the ticks' @@ -1839,6 +1841,7 @@ def tick_values(self, vmin, vmax): if not self.numticks > 1: raise RuntimeError('The number of ticks must be greater than 1 ' 'for LogLocator.') + # FIXME: The following was designed for integer division in py2. while numdec / stride + 1 > self.numticks: stride += 1 From 7c9acc03571e8b4b8c0bcb290cc525cb7f22b7bb Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Fri, 9 Sep 2016 17:07:49 -1000 Subject: [PATCH 2/2] Fix test, and make minor ticks work again --- lib/matplotlib/tests/test_ticker.py | 8 ++++---- lib/matplotlib/ticker.py | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index dfd8f429bb2c..aaf73fd5ed47 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -94,11 +94,11 @@ def test_LogLocator_set_params(): Should not exception. """ loc = mticker.LogLocator() - loc.set_params(numticks=8, numdecs=8, subs=[2.0], base=8) - nose.tools.assert_equal(loc.numticks, 8) + loc.set_params(numticks=7, numdecs=8, subs=[2.0], base=4) + nose.tools.assert_equal(loc.numticks, 7) nose.tools.assert_equal(loc.numdecs, 8) - nose.tools.assert_equal(loc.base, 8) - nose.tools.assert_equal(loc.subs, [2.0]) + nose.tools.assert_equal(loc._base, 4) + nose.tools.assert_equal(list(loc._subs), [2.0]) def test_NullLocator_set_params(): diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 2a3f16d93c79..02109e8bd991 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1757,13 +1757,11 @@ class LogLocator(Locator): Determine the tick locations for log axes """ - def __init__(self, base=10.0, subs=None, numdecs=4, numticks=15): + def __init__(self, base=10.0, subs=(1.0,), numdecs=4, numticks=15): """ place ticks on the location= base**i*subs[j] """ self.base(base) - if subs is None: - subs = [1.0] self.subs(subs) # this needs to be validated > 1 with traitlets self.numticks = numticks