8000 FIX negative value for log formatter is now better dealt with · matplotlib/matplotlib@0199251 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0199251

Browse files
committed
FIX negative value for log formatter is now better dealt with
1 parent 46083bf commit 0199251

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/matplotlib/ticker.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -898,18 +898,19 @@ def __call__(self, x, pos=None):
898898
if x == 0.0:
899899
return '0'
900900
sign = np.sign(x)
901+
x = abs(x)
901902
# only label the decades
902-
fx = math.log(abs(x)) / math.log(b)
903+
fx = math.log(x) / math.log(b)
903904
isDecade = is_close_to_int(fx)
904905
exponent = np.round(fx) if isDecade else np.floor(fx)
905-
coeff = np.round(abs(x) / b ** exponent)
906+
coeff = np.round(x / b ** exponent)
906907
if coeff in self.sublabel:
907908
if not isDecade and self.labelOnlyBase:
908909
return ''
909910
elif x > 10000:
910-
s = '%1.0e' % abs(x)
911+
s = '%1.0e' % x
911912
elif x < 1:
912-
s = '%1.0e' % abs(x)
913+
s = '%1.0e' % x
913914
else:
914915
s = self.pprint_val(x, self.d)
915916
if sign == -1:

0 commit comments

Comments
 (0)
0