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