FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix incorrect stride calculations in LogLocator.tick_values() by II-Day-II · Pull Request #25405 · matplotlib/matplotlib · GitHub

Repository navigation

20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,26 @@ def test_set_params(self):
assert loc._base == 4
assert list(loc._subs) == [2.0]

def test_tick_values_correct(self):
ll = mticker.LogLocator(subs=(1, 2, 5))
test_value = np.array([1.e-01, 2.e-01, 5.e-01, 1.e+00, 2.e+00, 5.e+00,
1.e+01, 2.e+01, 5.e+01, 1.e+02, 2.e+02, 5.e+02,
1.e+03, 2.e+03, 5.e+03, 1.e+04, 2.e+04, 5.e+04,
1.e+05, 2.e+05, 5.e+05, 1.e+06, 2.e+06, 5.e+06,
1.e+07, 2.e+07, 5.e+07, 1.e+08, 2.e+08, 5.e+08])
assert_almost_equal(ll.tick_values(1, 1e7), test_value)

def test_tick_values_not_empty(self):
mpl.rcParams['_internal.classic_mode'] = False
ll = mticker.LogLocator(subs=(1, 2, 5))
test_value = np.array([1.e-01, 2.e-01, 5.e-01, 1.e+00, 2.e+00, 5.e+00,
1.e+01, 2.e+01, 5.e+01, 1.e+02, 2.e+02, 5.e+02,
1.e+03, 2.e+03, 5.e+03, 1.e+04, 2.e+04, 5.e+04,
1.e+05, 2.e+05, 5.e+05, 1.e+06, 2.e+06, 5.e+06,
1.e+07, 2.e+07, 5.e+07, 1.e+08, 2.e+08, 5.e+08,
1.e+09, 2.e+09, 5.e+09])
assert_almost_equal(ll.tick_values(1, 1e8), test_value)


class TestNullLocator:
def test_set_params(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/ticker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ def tick_values(self, vmin, vmax):
# Get decades between major ticks.
stride = (max(math.ceil(numdec / (numticks - 1)), 1)
if mpl.rcParams['_internal.classic_mode'] else
(numdec + 1) // numticks + 1)
numdec // numticks + 1)

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

Back | FazBrowse Home | New Git URL