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 a6e954d

Browse filesBrowse files
committed
generalize label location for all bases
fix pep8 fix close to decade coefficients
1 parent 56e2871 commit a6e954d
Copy full SHA for a6e954d

File tree

Expand file treeCollapse file tree

1 file changed

+13
-12
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-12
lines changed

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ def pprint_val(self, x, d):
910910
s = s.rstrip('0').rstrip('.')
911911
return s
912912

913+
913914
class LogFormatterExponent(LogFormatter):
914915
"""
915916
Format values for log axis using ``exponent = log_base(value)``.
@@ -999,6 +1000,7 @@ def __call__(self, x, pos=None):
9991000
'%s%s^{%d}' %
10001001
(sign_string, base, nearest_long(fx))))
10011002

1003+
10021004
class LogFormatterSciNotation(LogFormatterMathtext):
10031005
"""
10041006
Format values following scientific notation in a logarithmic axis
@@ -1022,6 +1024,7 @@ def _non_decade_format(self, sign_string, base, fx, usetex):
10221024
return (r'$\mathdefault{%g\times%s^{%d}}$') % \
10231025
(coeff, base, exponent)
10241026

1027+
10251028
class LogitFormatter(Formatter):
10261029
"""
10271030
Probability formatter (using Math text).
@@ -1932,22 +1935,20 @@ def show_tick_label(self, ticklocs):
19321935
numdec = abs(vmax - vmin)
19331936

19341937
if numdec > 3:
1938+
# Label only bases
19351939
sublabel = set((1,))
1936-
elif numdec > 2:
1937-
sublabel = set((1, 3))
1938-
elif numdec > 1:
1939-
sublabel = set((1, 2, 5))
19401940
else:
1941-
sublabel = set((1, 2, 4, 7))
1941+
# Add labels between bases at log-spaced coefficients
1942+
c = np.logspace(0, 1, (4 - int(numdec)) + 1, base=b)
1943+
sublabel = set(np.round(c))
19421944

1943-
label = np.ones(ticklocs.size, dtype=np.bool)
1944-
for i, loc in enumerate(ticklocs):
1945-
exponent = math.floor(math.log(abs(loc)) / math.log(b))
1946-
coeff = loc / b ** nearest_long(exponent)
1947-
if nearest_long(coeff) not in sublabel:
1948-
label[i] = False
1945+
fx = np.log(abs(ticklocs)) / np.log(b)
1946+
exponents = np.array([np.round(x) if is_close_to_int(x)
1947+
else np.floor(x)
1948+
for x in fx])
1949+
coeffs = np.round(ticklocs / b ** exponents)
19491950

1950-
return label
1951+
return [c in sublabel for c in coeffs]
19511952

19521953
def view_limits(self, vmin, vmax):
19531954
'Try to choose the view limits intelligently'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.