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

Skip to content

Commit a06f343

Browse files
committed
Simplify stride calculations in loglocator.
These are just algebraic manipulations: In classic mode, we want the smallest stride so that numdec/stride+1 <= numticks i.e. stride >= numdec/(numticks-1) so stride is the ceil() of the RHS (and at least 1, to handle the case vmin==vmax). In nonclassic mode, we want the smallest stride so that numdec//stride+1 <= numticks, i.e. numdec//stride < numticks (everything is integer), i.e. numdec < numticks*stride- 1 i.e. stride > (numdec+1)/numticks so stride is 1 + the floor() of the LHS.
1 parent e0c9185 commit a06f343

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

lib/matplotlib/ticker.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,15 +2182,10 @@ def tick_values(self, vmin, vmax):
21822182
else:
21832183
subs = self._subs
21842184

2185-
# get decades between major ticks.
2186-
stride = 1
2187-
if rcParams['_internal.classic_mode']:
2188-
# Leave the bug left over from the PY2-PY3 transition.
2189-
while numdec / stride + 1 > numticks:
2190-
stride += 1
2191-
else:
2192-
while numdec // stride + 1 > numticks:
2193-
stride += 1
2185+
# Get decades between major ticks.
2186+
stride = (max(math.ceil(numdec / (numticks - 1)), 1)
2187+
if rcParams['_internal.classic_mode'] else
2188+
(numdec + 1) // numticks + 1)
21942189

21952190
# Does subs include anything other than 1?
21962191
have_subs = len(subs) > 1 or (len(subs) == 1 and subs[0] != 1.0)

0 commit comments

Comments
 (0)