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 a06f343

Browse filesBrowse 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
Copy full SHA for a06f343

File tree

Expand file treeCollapse file tree

1 file changed

+4
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-9
lines changed

‎lib/matplotlib/ticker.py

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