Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added ticker tests

  • Loading branch information...
commit bcdf06f516c58fd0bcbf11f81e72bb973f2fee4d 1 parent 8aa1e7d
Phil Elson authored August 13, 2012
22  lib/matplotlib/__init__.py
@@ -1003,26 +1003,28 @@ def tk_window_focus():
1003 1003
 
1004 1004
 default_test_modules = [
1005 1005
     'matplotlib.tests.test_agg',
  1006
+    'matplotlib.tests.test_axes',
1006 1007
     'matplotlib.tests.test_backend_svg',
1007 1008
     'matplotlib.tests.test_basic',
1008 1009
     'matplotlib.tests.test_cbook',
1009  
-    'matplotlib.tests.test_mlab',
1010  
-    'matplotlib.tests.test_transforms',
1011  
-    'matplotlib.tests.test_axes',
1012  
-    'matplotlib.tests.test_figure',
  1010
+    'matplotlib.tests.test_colorbar',
1013 1011
     'matplotlib.tests.test_dates',
1014  
-    'matplotlib.tests.test_spines',
  1012
+    'matplotlib.tests.test_delaunay',
  1013
+    'matplotlib.tests.test_figure',
1015 1014
     'matplotlib.tests.test_image',
1016  
-    'matplotlib.tests.test_simplification',
  1015
+    'matplotlib.tests.test_legend',
1017 1016
     'matplotlib.tests.test_mathtext',
  1017
+    'matplotlib.tests.test_mlab',
  1018
+    'matplotlib.tests.test_patches',
  1019
+    'matplotlib.tests.test_simplification',
  1020
+    'matplotlib.tests.test_spines',
1018 1021
     'matplotlib.tests.test_text',
  1022
+    'matplotlib.tests.test_ticker',
1019 1023
     'matplotlib.tests.test_tightlayout',
1020  
-    'matplotlib.tests.test_delaunay',
1021  
-    'matplotlib.tests.test_legend',
1022  
-    'matplotlib.tests.test_colorbar',
1023  
-    'matplotlib.tests.test_patches',
  1024
+    'matplotlib.tests.test_transforms',
1024 1025
     ]
1025 1026
 
  1027
+
1026 1028
 def test(verbosity=1):
1027 1029
     """run the matplotlib test suite"""
1028 1030
     old_backend = rcParams['backend']
51  lib/matplotlib/tests/test_ticker.py
... ...
@@ -0,0 +1,51 @@
  1
+from __future__ import print_function
  2
+from nose.tools import assert_equal, assert_raises
  3
+from numpy.testing import assert_almost_equal
  4
+import numpy as np
  5
+
  6
+import matplotlib.ticker as mticker
  7
+
  8
+
  9
+def test_MaxNLocator():
  10
+    loc = mticker.MaxNLocator(nbins=5)
  11
+    test_value = np.array([  20.,   40.,   60.,   80.,  100.])
  12
+    assert_almost_equal(loc.tick_values(20, 100), test_value)
  13
+
  14
+    test_value = np.array([ 0., 0.0002, 0.0004, 0.0006, 0.0008, 0.001])
  15
+    assert_almost_equal(loc.tick_values(0.001, 0.0001), test_value)
  16
+
  17
+    test_value = np.array([-1.0e+15, -5.0e+14, 0e+00, 5e+14, 1.0e+15])
  18
+    assert_almost_equal(loc.tick_values(-1e15, 1e15), test_value)
  19
+
  20
+
  21
+def test_LinearLocator():
  22
+    loc = mticker.LinearLocator(numticks=3)
  23
+    test_value = np.array([-0.8, -0.3,  0.2])
  24
+    assert_almost_equal(loc.tick_values(-0.8, 0.2), test_value)
  25
+
  26
+
  27
+def test_MultipleLocator():
  28
+    loc = mticker.MultipleLocator(base=3.147)
  29
+    test_value = np.array([-6.294, -3.147, 0., 3.147, 6.294, 9.441])
  30
+    assert_almost_equal(loc.tick_values(-7, 10), test_value)
  31
+
  32
+
  33
+def test_LogLocator():
  34
+    loc = mticker.LogLocator(numticks=5)
  35
+
  36
+    # make sure the 0 case is covered with an exception
  37
+    with assert_raises(ValueError):
  38
+        loc.tick_values(0, 1000)
  39
+
  40
+    test_value = np.array([1.00000000e-03, 1.00000000e-01, 1.00000000e+01,
  41
+                           1.00000000e+03, 1.00000000e+05, 1.00000000e+07])
  42
+    assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value)
  43
+
  44
+    loc = mticker.LogLocator(base=2)
  45
+    test_value = np.array([1., 2., 4., 8., 16., 32., 64., 128.])
  46
+    assert_almost_equal(loc.tick_values(1, 100), test_value)
  47
+
  48
+
  49
+if __name__=='__main__':
  50
+    import nose
  51
+    nose.runmodule(argv=['-s','--with-doctest'], exit=False)
8  lib/matplotlib/ticker.py
@@ -1319,13 +1319,13 @@ class LogLocator(Locator):
1319 1319
     Determine the tick locations for log axes
1320 1320
     """
1321 1321
 
1322  
-    def __init__(self, base=10.0, subs=[1.0], numdecs=4):
  1322
+    def __init__(self, base=10.0, subs=[1.0], numdecs=4, numticks=15):
1323 1323
         """
1324 1324
         place ticks on the location= base**i*subs[j]
1325 1325
         """
1326 1326
         self.base(base)
1327 1327
         self.subs(subs)
1328  
-        self.numticks = 15
  1328
+        self.numticks = numticks
1329 1329
         self.numdecs = numdecs
1330 1330
 
1331 1331
     def base(self,base):
@@ -1359,7 +1359,9 @@ def tick_values(self, vmin, vmax):
1359 1359
             return ticklocs
1360 1360
 
1361 1361
         if vmin <= 0.0:
1362  
-            vmin = self.axis.get_minpos()
  1362
+            if self.axis is not None:
  1363
+                vmin = self.axis.get_minpos()
  1364
+
1363 1365
             if vmin <= 0.0 or not np.isfinite(vmin):
1364 1366
                 raise ValueError(
1365 1367
                     "Data has no positive values, and therefore can not be log-scaled.")

0 notes on commit bcdf06f

Please sign in to comment.
Something went wrong with that request. Please try again.