|
3 | 3 |
|
4 | 4 | from matplotlib.externals import six |
5 | 5 | import nose.tools |
6 | | -from nose.tools import assert_raises |
| 6 | +from nose.tools import assert_equal, assert_raises |
7 | 7 | from numpy.testing import assert_almost_equal |
8 | 8 | import numpy as np |
9 | 9 | import matplotlib |
@@ -159,6 +159,53 @@ def test_SymmetricalLogLocator_set_params(): |
159 | 159 | nose.tools.assert_equal(sym.numticks, 8) |
160 | 160 |
|
161 | 161 |
|
| 162 | +@cleanup |
| 163 | +def test_ScalarFormatter_offset_value(): |
| 164 | + fig, ax = plt.subplots() |
| 165 | + formatter = ax.get_xaxis().get_major_formatter() |
| 166 | + |
| 167 | + def check_offset_for(left, right, offset): |
| 168 | + ax.set_xlim(left, right) |
| 169 | + # Update ticks. |
| 170 | + next(ax.get_xaxis().iter_ticks()) |
| 171 | + assert_equal(formatter.offset, offset) |
| 172 | + |
| 173 | + test_data = [(123, 189, 0), |
| 174 | + (-189, -123, 0), |
| 175 | + (12341, 12349, 12340), |
| 176 | + (-12349, -12341, -12340), |
| 177 | + (99999.5, 100010.5, 100000), |
| 178 | + (-100010.5, -99999.5, -100000), |
| 179 | + (99990.5, 100000.5, 100000), |
| 180 | + (-100000.5, -99990.5, -100000), |
| 181 | + (1233999, 1234001, 1234000), |
| 182 | + (-1234001, -1233999, -1234000), |
| 183 | + (1, 1, 1), |
| 184 | + (123, 123, 120), |
| 185 | + # Test cases courtesy of @WeatherGod |
| 186 | + (.4538, .4578, .45), |
| 187 | + (3789.12, 3783.1, 3780), |
| 188 | + (45124.3, 45831.75, 45000), |
| 189 | + (0.000721, 0.0007243, 0.00072), |
| 190 | + (12592.82, 12591.43, 12590), |
| 191 | + (9., 12., 0), |
| 192 | + (900., 1200., 0), |
| 193 | + (1900., 1200., 0), |
| 194 | + (0.99, 1.01, 1), |
| 195 | + (9.99, 10.01, 10), |
| 196 | + (99.99, 100.01, 100), |
| 197 | + (5.99, 6.01, 6), |
| 198 | + (15.99, 16.01, 16), |
| 199 | + (-0.452, 0.492, 0), |
| 200 | + (-0.492, 0.492, 0), |
| 201 | + (12331.4, 12350.5, 12300), |
| 202 | + (-12335.3, 12335.3, 0)] |
| 203 | + |
| 204 | + for left, right, offset in test_data: |
| 205 | + yield check_offset_for, left, right, offset |
| 206 | + yield check_offset_for, right, left, offset |
| 207 | + |
| 208 | + |
162 | 209 | def _logfe_helper(formatter, base, locs, i, expected_result): |
163 | 210 | vals = base**locs |
164 | 211 | labels = [formatter(x, pos) for (x, pos) in zip(vals, i)] |
|
0 commit comments