Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef7888d

Browse files
authored
Merge pull request #18786 from meeseeksmachine/auto-backport-of-pr-18754-on-v3.3.x
Backport PR #18754 on branch v3.3.x (FIX: make sure we have more than 1 tick with small log ranges)
2 parents f51e408 + 1c509c3 commit ef7888d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,3 +1347,13 @@ def test_bad_locator_subs(sub):
13471347
ll = mticker.LogLocator()
13481348
with pytest.raises(ValueError):
13491349
ll.subs(sub)
1350+
1351+
1352+
@pytest.mark.parametrize('numticks', [1, 2, 3, 9])
1353+
@pytest.mark.style('default')
1354+
def test_small_range_loglocator(numticks):
1355+
ll = mticker.LogLocator()
1356+
ll.set_params(numticks=numticks)
1357+
for top in [5, 7, 9, 11, 15, 50, 100, 1000]:
1358+
ticks = ll.tick_values(.5, top)
1359+
assert (np.diff(np.log10(ll.tick_values(6, 150))) == 1).all()

lib/matplotlib/ticker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,13 @@ def tick_values(self, vmin, vmax):
25002500
if mpl.rcParams['_internal.classic_mode'] else
25012501
(numdec + 1) // numticks + 1)
25022502

2503+
# if we have decided that the stride is as big or bigger than
2504+
# the range, clip the stride back to the available range - 1
2505+
# with a floor of 1. This prevents getting axis with only 1 tick
2506+
# visible.
2507+
if stride >= numdec:
2508+
stride = max(1, numdec - 1)
2509+
25032510
# Does subs include anything other than 1? Essentially a hack to know
25042511
# whether we're a major or a minor locator.
25052512
have_subs = len(subs) > 1 or (len(subs) == 1 and subs[0] != 1.0)

0 commit comments

Comments
 (0)