Skip to content

Commit 71dd3ae

Browse files
authored
Merge pull request #13126 from jklymak/fix-minor-log
FIX: minor log ticks overwrite
2 parents 910f9fd + 1f70d7a commit 71dd3ae

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ def test_switch_to_autolocator(self):
183183
loc = mticker.LogLocator(subs="all")
184184
assert_array_equal(loc.tick_values(0.45, 0.55),
185185
[0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56])
186+
# check that we *skip* 1.0, and 10, because this is a minor locator
187+
loc = mticker.LogLocator(subs=np.arange(2, 10))
188+
assert 1.0 not in loc.tick_values(0.9, 20.)
189+
assert 10.0 not in loc.tick_values(0.9, 20.)
186190

187191
def test_set_params(self):
188192
"""

lib/matplotlib/ticker.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,9 +2093,7 @@ def is_decade(x, base=10):
20932093

20942094

20952095
def is_close_to_int(x):
2096-
if not np.isfinite(x):
2097-
return False
2098-
return abs(x - round(x)) < 1e-10
2096+
return abs(x - np.round(x)) < 1e-10
20992097

21002098

21012099
class LogLocator(Locator):
@@ -2256,7 +2254,12 @@ def tick_values(self, vmin, vmax):
22562254
# If we're a minor locator *that expects at least two ticks per
22572255
# decade* and the major locator stride is 1 and there's no more
22582256
# than one minor tick, switch to AutoLocator.
2259-
return AutoLocator().tick_values(vmin, vmax)
2257+
ticklocs = AutoLocator().tick_values(vmin, vmax)
2258+
# Don't overstrike the major labels. Assumes major locs are
2259+
# at b = self._base
2260+
ticklocs = ticklocs[
2261+
~is_close_to_int(np.log(ticklocs) / np.log(b))]
2262+
return ticklocs
22602263
return self.raise_if_exceeds(ticklocs)
22612264

22622265
def view_limits(self, vmin, vmax):

0 commit comments

Comments
 (0)