Skip to content

Commit ec9ecbc

Browse files
committed
Simplify log locator logic
1 parent 73c32d6 commit ec9ecbc

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ class TestLogLocator:
198198
'vmin, vmax, expected_ticks',
199199
(
200200
[1, 10, [1, 10]],
201-
[0.9, 10.1, [1, 10]],
202-
[0.9, 9, [1]],
203-
[1.1, 11, [10]],
204-
[0.5, 983, [1, 10, 100]]
201+
[0.9, 10.1, [0.1, 1, 10, 100]],
202+
[0.9, 9, [0.1, 1, 10]],
203+
[1.1, 11, [1, 10, 100]],
204+
[0.5, 983, [0.1, 1, 10, 100, 1000]]
205205
)
206206
)
207207
def test_tick_locs(self, vmin, vmax, expected_ticks):
@@ -210,13 +210,13 @@ def test_tick_locs(self, vmin, vmax, expected_ticks):
210210

211211
def test_basic(self):
212212
loc = mticker.LogLocator(numticks=5)
213-
test_value = np.array([1.00000000e-05, 1.00000000e-03, 1.00000000e-01,
213+
test_value = np.array([1.00000000e-03, 1.00000000e-01,
214214
1.00000000e+01, 1.00000000e+03, 1.00000000e+05,
215-
1.00000000e+07, 1.000000000e+09])
216-
assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value)
215+
1.00000000e+07])
216+
assert_almost_equal(loc.tick_values(1e-3, 1.1e5), test_value)
217217

218218
loc = mticker.LogLocator(base=2)
219-
test_value = np.array([0.5, 1., 2., 4., 8., 16., 32., 64., 128., 256.])
219+
test_value = np.array([1., 2., 4., 8., 16., 32., 64., 128.])
220220
assert_almost_equal(loc.tick_values(1, 100), test_value)
221221

222222
def test_invalid_lim_error(self):

lib/matplotlib/ticker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,8 +2408,10 @@ def tick_values(self, vmin, vmax):
24082408
# whether we're a major or a minor locator.
24092409
have_subs = len(subs) > 1 or (len(subs) == 1 and subs[0] != 1.0)
24102410

2411-
decades = np.arange(math.floor(log_vmin) - stride,
2412-
math.ceil(log_vmax) + 2 * stride, stride)
2411+
# Return one tick below (or equal to) vmin,
2412+
# and one tick above (or equal to) vmax
2413+
decades = np.arange(math.floor(log_vmin),
2414+
math.ceil(log_vmax) + stride, stride)
24132415

24142416
if hasattr(self, '_transform'):
24152417
ticklocs = self._transform.inverted().transform(decades)

0 commit comments

Comments
 (0)