Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Fixed tests for python3 compatibility. Added test for LinearLocator.
  • Loading branch information
leeonadoh committed Mar 3, 2015
commit 5cf67df9536b6ffb3c11ae9759d3b78734eedb83
14 changes: 12 additions & 2 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def test_AutoMinorLocator():

def test_LogLocator():
loc = mticker.LogLocator(numticks=5)

assert_raises(ValueError, loc.tick_values, 0, 1000)

test_value = np.array([1.00000000e-05, 1.00000000e-03, 1.00000000e-01,
Expand All @@ -65,6 +64,17 @@ def test_LogLocator():
assert_almost_equal(loc.tick_values(1, 100), test_value)


def test_LinearLocator_set_params():
"""
Create linear locator with presets={}, numticks=2 and change it to
something else. See if change was successful. Should not exception.
"""
loc = mticker.LinearLocator(numticks=2)
loc.set_params(numticks=8, presets={(0, 1): []})
nose.tools.assert_equal(loc.numticks, 8)
nose.tools.assert_equal(loc.presets, {(0, 1): []})


def test_LogLocator_set_params():
"""
Create log locator with default value, base=10.0, subs=[1.0], numdecs=4,
Expand All @@ -86,7 +96,7 @@ def test_NullLocator_set_params():
Should not exception, and should raise a warning.
"""
loc = mticker.NullLocator()
with warnings.catch_warnings(True) as w:
with warnings.catch_warnings(record=True) as w:
loc.set_params()
nose.tools.assert_equal(len(w), 1)

Expand Down
27 changes: 14 additions & 13 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ def tick_values(self, vmin, vmax):
raise NotImplementedError('Derived must override')

def set_params(self, **kwargs):
"""
Do nothing, and rase a warning. Any locator class not supporting the
set_params() function will call this.
"""
warnings.warn("'set_params()' not defined for locator of type " +
str(type(self)))

Expand Down Expand Up @@ -1032,6 +1036,7 @@ def __init__(self, base, offset):
self.offset = offset

def set_params(self, base=None, offset=None):
"""Set parameters within this locator"""
if base is not None:
self.base = base
if offset is not None:
Expand Down Expand Up @@ -1065,8 +1070,9 @@ def __init__(self, locs, nbins=None):
self.nbins = max(self.nbins, 2)

def set_params(self, nbins=None):
"""Set parameters within this locator."""
if nbins is not None:
self.nbins=nbins
self.nbins = nbins

def __call__(self):
return self.tick_values(None, None)
Expand Down Expand Up @@ -1133,12 +1139,9 @@ def __init__(self, numticks=None, presets=None):
self.presets = presets

def set_params(self, numticks=None, presets=None):
"""
[numticks : Int,present : dict] ->None

"""
"""Set parameters within this locator."""
if presets is not None:
self.presets = presents
self.presets = presets
if numticks is not None:
self.numticks = numticks

Expand Down Expand Up @@ -1245,10 +1248,8 @@ def __init__(self, base=1.0):
self._base = Base(base)

def set_params(self, base):
"""

"""
if base is not None :
"""Set parameters within this locator."""
if base is not None:
self.base = base

def __call__(self):
Expand Down Expand Up @@ -1352,6 +1353,7 @@ def __init__(self, *args, **kwargs):
self.set_params(**kwargs)

def set_params(self, **kwargs):
"""Set parameters within this locator."""
if 'nbins' in kwargs:
self._nbins = int(kwargs['nbins'])
if 'trim' in kwargs:
Expand Down Expand Up @@ -1487,6 +1489,7 @@ def __init__(self, base=10.0, subs=[1.0], numdecs=4, numticks=15):
self.numdecs = numdecs

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
if subs is not None:
Expand Down Expand Up @@ -1624,9 +1627,7 @@ def __init__(self, transform, subs=None):
self.numticks = 15

def set_params(self, subs=None, numticks=None):
"""

"""
"""Set parameters within this locator."""
if numticks is not None:
self.numticks = numticks
if subs is not None:
Expand Down