Skip to content

Commit fc3bc64

Browse files
committed
FIX: log axes: don't choose major ticks as a minor tick
1 parent af8a720 commit fc3bc64

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/ticker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ def is_decade(x, base=10):
20952095
def is_close_to_int(x):
20962096
if not np.isfinite(x):
20972097
return False
2098-
return abs(x - round(x)) < 1e-10
2098+
return abs(x - np.round(x)) < 1e-10
20992099

21002100

21012101
class LogLocator(Locator):
@@ -2256,7 +2256,11 @@ def tick_values(self, vmin, vmax):
22562256
# If we're a minor locator *that expects at least two ticks per
22572257
# decade* and the major locator stride is 1 and there's no more
22582258
# than one minor tick, switch to AutoLocator.
2259-
return AutoLocator().tick_values(vmin, vmax)
2259+
ticklocs = AutoLocator().tick_values(vmin, vmax)
2260+
# Don't overstrike the major labels.
2261+
ticklocs = [t for t in ticklocs if
2262+
~is_close_to_int(np.log(t) / np.log(b))]
2263+
return ticklocs
22602264
return self.raise_if_exceeds(ticklocs)
22612265

22622266
def view_limits(self, vmin, vmax):

0 commit comments

Comments
 (0)