Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c509c3

Browse filesBrowse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #18754: FIX: make sure we have more than 1 tick with small log ranges
1 parent f51e408 commit 1c509c3
Copy full SHA for 1c509c3

File tree

Expand file treeCollapse file tree

2 files changed

+17
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-0
lines changed

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+10Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+7Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.