8000 prevent subticks from being added to center zero label · matplotlib/matplotlib@b26b598 · GitHub
[go: up one dir, main page]

Skip to content

Commit b26b598

Browse files
committed
prevent subticks from being added to center zero label
1 parent b8364c6 commit b26b598

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/matplotlib/ticker.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ class LogFormatterMathtext(LogFormatter):
10631063
"""
10641064
Format values for log axis using ``exponent = log_base(value)``.
10651065
"""
1066+
_min_zero_pos = None
10661067

10671068
def _non_decade_format(self, sign_string, base, fx, usetex):
10681069
'Return string for non-decade locations'
@@ -1076,16 +1077,21 @@ def __call__(self, x, pos=None):
10761077
"""
10771078
Return the format for tick value `x`.
10781079
1079-
The position `pos` is ignored.
1080+
The position `pos` is used for SymLogNorm for ensuring
1081+
only one zero entry is present.
10801082
"""
10811083
usetex = rcParams['text.usetex']
10821084
min_exp = rcParams['axes.formatter.min_exponent']
1083108 10000 5

10841086
if x == 0: # Symlog
1085-
if usetex:
1086-
return '$0$'
1087+
if self._min_zero_pos is None:
1088+
self._min_zero_pos = pos
1089+
if usetex:
1090+
return '$0$'
1091+
else:
1092+
return '$%s$' % _mathdefault('0')
10871093
else:
1088-
return '$%s$' % _mathdefault('0')
1094+
return ''
10891095

10901096
sign_string = '-' if x < 0 else ''
10911097
x = abs(x)
@@ -2315,7 +2321,7 @@ def get_log_range(lo, hi):
23152321

23162322
if has_c:
23172323
if has_b:
2318-
c_range = get_log_range(t, vmax + 1)
2324+
c_range = get_log_range(t, vmax + 1) # Why the +1?
23192325
else:
23202326
c_range = get_log_range(vmin, vmax + 1)
23212327
else:
@@ -2346,7 +2352,10 @@ def get_log_range(lo, hi):
23462352
if len(subs) > 1 or subs[0] != 1.0:
23472353
ticklocs = []
23482354
for decade in decades:
2349-
ticklocs.extend(subs * decade)
2355+
if decade == 0:
2356+
ticklocs.append(decade)
2357+
else:
2358+
ticklocs.extend(subs * decade)
23502359
else:
23512360
ticklocs = decades
23522361

0 commit comments

Comments
 (0)
0