@@ -50,6 +50,32 @@ def test_LogLocator():
50
50
test_value = np .array ([0.5 , 1. , 2. , 4. , 8. , 16. , 32. , 64. , 128. , 256. ])
51
51
assert_almost_equal (loc .tick_values (1 , 100 ), test_value )
52
52
53
+ def test_LogFormatterExponent ():
54
+ class FakeAxis (object ):
55
+ """Allow Formatter to be called without having a "full" plot set up."""
56
+ def get_view_interval (self ):
57
+ return 1 , 10
58
+
59
+ i = np .arange (- 3 , 4 , dtype = float )
60
+ expected_result = ['-3' , '-2' , '-1' , '0' , '1' , '2' , '3' ]
61
+ for base in [2 , 5 , 10 , np .pi ]:
62
+ formatter = mticker .LogFormatterExponent (base = base )
63
+ formatter .axis = FakeAxis ()
64
+ vals = base ** i
65
+ labels = [formatter (x , pos ) for (x , pos ) in zip (vals , i )]
66
+ nose .tools .assert_equal (labels , expected_result )
67
+
68
+ # Should be a blank string for non-integer powers if labelOnlyBase=True
69
+ formatter = mticker .LogFormatterExponent (base = 10 , labelOnlyBase = True )
70
+ formatter .axis = FakeAxis ()
71
+ nose .tools .assert_equal (formatter (10 ** 0.1 ), '' )
72
+
73
+ # Otherwise, non-integer powers should be nicely formatted
74
+ formatter = mticker .LogFormatterExponent (base = 10 , labelOnlyBase = False )
75
+ formatter .axis = FakeAxis ()
76
+ nose .tools .assert_equal (formatter (10 ** 0.1 ), '0.1' )
77
+ nose .tools .assert_equal (formatter (10 ** 0.00001 ), '1e-05' )
78
+ nose .tools .assert_equal (formatter (10 ** - 0.2 ), '-0.2' )
53
79
54
80
def test_use_offset ():
55
81
for use_offset in [True , False ]:
0 commit comments