Skip to content

Commit fdcc86a

Browse files
authored
Merge pull request #30348 from anntzer/minorlog
Keep default minor log ticks if there's 1 major & 1 minor tick.
2 parents b19a68a + 315c4fb commit fdcc86a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ def test_switch_to_autolocator(self):
356356
loc = mticker.LogLocator(subs=np.arange(2, 10))
357357
assert 1.0 not in loc.tick_values(0.9, 20.)
358358
assert 10.0 not in loc.tick_values(0.9, 20.)
359+
# don't switch if there's already one major and one minor tick (10 & 20)
360+
loc = mticker.LogLocator(subs="auto")
361+
tv = loc.tick_values(10, 20)
362+
assert_array_equal(tv[(10 <= tv) & (tv <= 20)], [20])
359363

360364
def test_set_params(self):
361365
"""

lib/matplotlib/ticker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,10 +2522,12 @@ def tick_values(self, vmin, vmax):
25222522

25232523
if (len(subs) > 1
25242524
and stride == 1
2525-
and ((vmin <= ticklocs) & (ticklocs <= vmax)).sum() <= 1):
2525+
and (len(decades) - 2 # major
2526+
+ ((vmin <= ticklocs) & (ticklocs <= vmax)).sum()) # minor
2527+
<= 1):
25262528
# If we're a minor locator *that expects at least two ticks per
25272529
# decade* and the major locator stride is 1 and there's no more
2528-
# than one minor tick, switch to AutoLocator.
2530+
# than one major or minor tick, switch to AutoLocator.
25292531
return AutoLocator().tick_values(vmin, vmax)
25302532
else:
25312533
return self.raise_if_exceeds(ticklocs)

0 commit comments

Comments
 (0)