MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _pprint_val

Method _pprint_val

lib/matplotlib/ticker.py:1107–1127  ·  view source on GitHub ↗
(self, x, d)

Source from the content-addressed store, hash-verified

1105 return ('%-12g' % value).rstrip()
1106
1107 def _pprint_val(self, x, d):
1108 # If the number is not too big and it's an int, format it as an int.
1109 if abs(x) < 1e4 and x == int(x):
1110 return '%d' % x
1111 fmt = ('%1.3e' if d < 1e-2 else
1112 '%1.3f' if d <= 1 else
1113 '%1.2f' if d <= 10 else
1114 '%1.1f' if d <= 1e5 else
1115 '%1.1e')
1116 s = fmt % x
1117 tup = s.split('e')
1118 if len(tup) == 2:
1119 mantissa = tup[0].rstrip('0').rstrip('.')
1120 exponent = int(tup[1])
1121 if exponent:
1122 s = '%se%d' % (mantissa, exponent)
1123 else:
1124 s = mantissa
1125 else:
1126 s = s.rstrip('0').rstrip('.')
1127 return s
1128
1129
1130class LogFormatterExponent(LogFormatter):

Callers 3

_num_to_stringMethod · 0.95
test_pprintMethod · 0.95
_num_to_stringMethod · 0.80

Calls

no outgoing calls

Tested by 1

test_pprintMethod · 0.76