Skip to content

FIX: LogLocator.set_params() was clobbering methods #7045

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

Merged
merged 2 commits into from
Sep 11, 2016
Merged
Show file tree
Hide file tree
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: 4 additions & 4 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
11 changes: 6 additions & 5 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ 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=(1.0,), numdecs=4, numticks=15):
"""
place ticks on the location= base**i*subs[j]
"""
Expand All @@ -1770,9 +1770,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:
Expand All @@ -1782,7 +1782,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):
"""
Expand All @@ -1791,7 +1791,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'
Expand Down Expand Up @@ -1839,6 +1839,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

Expand Down