|
| 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) |
0 commit comments