8000 Merge pull request #25405 from haval0/issue/24092 · matplotlib/matplotlib@9e52bc8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e52bc8

Browse files
authored
Merge pull request #25405 from haval0/issue/24092
Fix incorrect stride calculations in LogLocator.tick_values()
2 parents 31e5682 + e1813b5 commit 9e52bc8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,26 @@ def test_set_params(self):
239239
assert loc._base == 4
240240
assert list(loc._subs) == [2.0]
241241

242+
def test_tick_values_correct(self):
243+
ll = mticker.LogLocator(subs=(1, 2, 5))
244+
test_value = np.array([1.e-01, 2.e-01, 5.e-01, 1.e+00, 2.e+00, 5.e+00,
245+
1.e+01, 2.e+01, 5.e+01, 1.e+02, 2.e+02, 5.e+02,
246+
1.e+03, 2.e+03, 5.e+03, 1.e+04, 2.e+04, 5.e+04,
247+
1.e+05, 2.e+05, 5.e+05, 1.e+06, 2.e+06, 5.e+06,
248+
1.e+07, 2.e+07, 5.e+07, 1.e+08, 2.e+08, 5.e+08])
249+
assert_almost_equal(ll.tick_values(1, 1e7), test_value)
250+
251+
def test_tick_values_not_empty(self):
252+
mpl.rcParams['_internal.classic_mode'] = False
253+
ll = mticker.LogLocator(subs=(1, 2, 5))
254+
test_value = np.array([1.e-01, 2.e-01, 5.e-01, 1.e+00, 2.e+00, 5.e+00,
255+
1.e+01, 2.e+01, 5.e+01, 1.e+02, 2.e+02, 5.e+02,
256+
1.e+03, 2.e+03, 5.e+03, 1.e+04, 2.e+04, 5.e+04,
257+
1.e+05, 2.e+05, 5.e+05, 1.e+06, 2.e+06, 5.e+06,
258+
1.e+07, 2.e+07, 5.e+07, 1.e+08, 2.e+08, 5.e+08,
259+
1.e+09, 2.e+09, 5.e+09])
260+
assert_almost_equal(ll.tick_values(1, 1e8), test_value)
261+
242262

243263
class TestNullLocator:
244264
def test_set_params(self):

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ def tick_values(self, vmin, vmax):
23362336
# Get decades between major ticks.
23372337
stride = (max(math.ceil(numdec / (numticks - 1)), 1)
23382338
if mpl.rcParams['_internal.classic_mode'] else
2339-
(numdec + 1) // numticks + 1)
2339+
numdec // numticks + 1)
23402340

23412341
# if we have decided that the stride is as big or bigger than
23422342
# the range, clip the stride back to the available range - 1

0 commit comments

Comments
 (0)
0