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

Skip to content

Commit bcdf06f

Browse files
committed
Added ticker tests
1 parent 8aa1e7d commit bcdf06f

File tree

3 files changed

+68
-13
lines changed

3 files changed

+68
-13
lines changed

lib/matplotlib/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,26 +1003,28 @@ def tk_window_focus():
10031003

10041004
default_test_modules = [
10051005
'matplotlib.tests.test_agg',
1006+
'matplotlib.tests.test_axes',
10061007
'matplotlib.tests.test_backend_svg',
10071008
'matplotlib.tests.test_basic',
10081009
'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',
10131011
'matplotlib.tests.test_dates',
1014-
'matplotlib.tests.test_spines',
1012+
'matplotlib.tests.test_delaunay',
1013+
'matplotlib.tests.test_figure',
10151014
'matplotlib.tests.test_image',
1016-
'matplotlib.tests.test_simplification',
1015+
'matplotlib.tests.test_legend',
10171016
'matplotlib.tests.test_mathtext',
1017+
'matplotlib.tests.test_mlab',
1018+
'matplotlib.tests.test_patches',
1019+
'matplotlib.tests.test_simplification',
1020+
'matplotlib.tests.test_spines',
10181021
'matplotlib.tests.test_text',
1022+
'matplotlib.tests.test_ticker',
10191023
'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',
10241025
]
10251026

1027+
10261028
def test(verbosity=1):
10271029
"""run the matplotlib test suite"""
10281030
old_backend = rcParams['backend']

lib/matplotlib/tests/test_ticker.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

lib/matplotlib/ticker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,13 +1319,13 @@ class LogLocator(Locator):
13191319
Determine the tick locations for log axes
13201320
"""
13211321

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):
13231323
"""
13241324
place ticks on the location= base**i*subs[j]
13251325
"""
13261326
self.base(base)
13271327
self.subs(subs)
1328-
self.numticks = 15
1328+
self.numticks = numticks
13291329
self.numdecs = numdecs
13301330

13311331
def base(self,base):
@@ -1359,7 +1359,9 @@ def tick_values(self, vmin, vmax):
13591359
return ticklocs
13601360

13611361
if vmin <= 0.0:
1362-
vmin = self.axis.get_minpos()
1362+
if self.axis is not None:
1363+
vmin = self.axis.get_minpos()
1364+
13631365
if vmin <= 0.0 or not np.isfinite(vmin):
13641366
raise ValueError(
13651367
"Data has no positive values, and therefore can not be log-scaled.")

0 commit comments

Comments
 (0)