Permalink
Browse files

Added ticker tests

  • Loading branch information...
1 parent 8aa1e7d commit bcdf06f516c58fd0bcbf11f81e72bb973f2fee4d @pelson committed Aug 13, 2012
Showing with 68 additions and 13 deletions.
  1. +12 −10 lib/matplotlib/__init__.py
  2. +51 −0 lib/matplotlib/tests/test_ticker.py
  3. +5 −3 lib/matplotlib/ticker.py
View
@@ -1003,26 +1003,28 @@ def tk_window_focus():
default_test_modules = [
'matplotlib.tests.test_agg',
+ 'matplotlib.tests.test_axes',
'matplotlib.tests.test_backend_svg',
'matplotlib.tests.test_basic',
'matplotlib.tests.test_cbook',
- 'matplotlib.tests.test_mlab',
- 'matplotlib.tests.test_transforms',
- 'matplotlib.tests.test_axes',
- 'matplotlib.tests.test_figure',
+ 'matplotlib.tests.test_colorbar',
'matplotlib.tests.test_dates',
- 'matplotlib.tests.test_spines',
+ 'matplotlib.tests.test_delaunay',
+ 'matplotlib.tests.test_figure',
'matplotlib.tests.test_image',
- 'matplotlib.tests.test_simplification',
+ 'matplotlib.tests.test_legend',
'matplotlib.tests.test_mathtext',
+ 'matplotlib.tests.test_mlab',
+ 'matplotlib.tests.test_patches',
+ 'matplotlib.tests.test_simplification',
+ 'matplotlib.tests.test_spines',
'matplotlib.tests.test_text',
+ 'matplotlib.tests.test_ticker',
'matplotlib.tests.test_tightlayout',
- 'matplotlib.tests.test_delaunay',
- 'matplotlib.tests.test_legend',
- 'matplotlib.tests.test_colorbar',
- 'matplotlib.tests.test_patches',
+ 'matplotlib.tests.test_transforms',
]
+
def test(verbosity=1):
"""run the matplotlib test suite"""
old_backend = rcParams['backend']
@@ -0,0 +1,51 @@
+from __future__ import print_function
+from nose.tools import assert_equal, assert_raises
+from numpy.testing import assert_almost_equal
+import numpy as np
+
+import matplotlib.ticker as mticker
+
+
+def test_MaxNLocator():
+ loc = mticker.MaxNLocator(nbins=5)
+ test_value = np.array([ 20., 40., 60., 80., 100.])
+ assert_almost_equal(loc.tick_values(20, 100), test_value)
+
+ test_value = np.array([ 0., 0.0002, 0.0004, 0.0006, 0.0008, 0.001])
+ assert_almost_equal(loc.tick_values(0.001, 0.0001), test_value)
+
+ test_value = np.array([-1.0e+15, -5.0e+14, 0e+00, 5e+14, 1.0e+15])
+ assert_almost_equal(loc.tick_values(-1e15, 1e15), test_value)
+
+
+def test_LinearLocator():
+ loc = mticker.LinearLocator(numticks=3)
+ test_value = np.array([-0.8, -0.3, 0.2])
+ assert_almost_equal(loc.tick_values(-0.8, 0.2), test_value)
+
+
+def test_MultipleLocator():
+ loc = mticker.MultipleLocator(base=3.147)
+ test_value = np.array([-6.294, -3.147, 0., 3.147, 6.294, 9.441])
+ assert_almost_equal(loc.tick_values(-7, 10), test_value)
+
+
+def test_LogLocator():
+ loc = mticker.LogLocator(numticks=5)
+
+ # make sure the 0 case is covered with an exception
+ with assert_raises(ValueError):
+ loc.tick_values(0, 1000)
+
+ test_value = np.array([1.00000000e-03, 1.00000000e-01, 1.00000000e+01,
+ 1.00000000e+03, 1.00000000e+05, 1.00000000e+07])
+ assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value)
+
+ loc = mticker.LogLocator(base=2)
+ test_value = np.array([1., 2., 4., 8., 16., 32., 64., 128.])
+ assert_almost_equal(loc.tick_values(1, 100), test_value)
+
+
+if __name__=='__main__':
+ import nose
+ nose.runmodule(argv=['-s','--with-doctest'], exit=False)
View
@@ -1319,13 +1319,13 @@ class LogLocator(Locator):
Determine the tick locations for log axes
"""
- def __init__(self, base=10.0, subs=[1.0], numdecs=4):
+ 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)
self.subs(subs)
- self.numticks = 15
+ self.numticks = numticks
self.numdecs = numdecs
def base(self,base):
@@ -1359,7 +1359,9 @@ def tick_values(self, vmin, vmax):
return ticklocs
if vmin <= 0.0:
- vmin = self.axis.get_minpos()
+ if self.axis is not None:
+ vmin = self.axis.get_minpos()
+
if vmin <= 0.0 or not np.isfinite(vmin):
raise ValueError(
"Data has no positive values, and therefore can not be log-scaled.")

0 comments on commit bcdf06f

Please sign in to comment.