@@ -1184,19 +1184,8 @@ class EngFormatter(Formatter):
1184
1184
"""
1185
1185
Formats axis values using engineering prefixes to represent powers
1186
1186
of 1000, plus a specified unit, e.g., 10 MHz instead of 1e7.
1187
-
1188
- `unit` is a string containing the abbreviated name of the unit,
1189
- suitable for use with single-letter representations of powers of
1190
- 1000. For example, 'Hz' or 'm'.
1191
-
1192
- `places` is the precision with which to display the number,
1193
- specified in digits after the decimal point (there will be between
1194
- one and three digits before the decimal point).
1195
-
1196
- `sep` is the separator (a string) that is used between the number
1197
- and the prefix/unit. For example, '3.14 mV' if `sep` is " " (default)
1198
- and '3.14mV' if `sep` is "".
1199
1187
"""
1188
+
1200
1189
# The SI engineering prefixes
1201
1190
ENG_PREFIXES = {
1202
1191
- 24 : "y" ,
@@ -1222,20 +1211,26 @@ def __init__(self, unit="", places=None, sep=" "):
1222
1211
"""
1223
1212
Parameters
1224
1213
----------
1225
- unit: string (default: "")
1226
- Unit symbol to use.
1227
-
1228
- places: int (default: None)
1229
- Precision, i.e. number of digits after the decimal point.
1230
- If it is None, falls back to the floating point format '%g'.
1231
-
1232
- sep: string (default: " ")
1233
-
6D40
String used between the value and the prefix/unit. Beside the
1234
- default behavior, some other useful use cases may be:
1235
- * sep="" to append directly the prefix/unit to the value;
1236
- * sep="\\ u2009" to use a thin space;
1237
- * sep="\\ u202f" to use a narrow no-break space;
1238
- * sep="\\ u00a0" to use a no-break space.
1214
+ unit : str (default: "")
1215
+ Unit symbol to use, suitable for use with single-letter
1216
+ representations of powers of 1000. For example, 'Hz' or 'm'.
1217
+
1218
+ places : int (default: None)
1219
+ Precision with which to display the number, specified in
1220
+ digits after the decimal point (there will be between one
1221
+ and three digits before the decimal point). If it is None,
1222
+ falls back to the floating point format '%g'.
1223
+
1224
+ sep : str (default: " ")
1225
+ Separator used between the value and the prefix/unit. For
1226
+ example, one get '3.14 mV' if ``sep`` is " " (default) and
1227
+ '3.14mV' if ``sep`` is "". Besides the default behavior, some
1228
+ other useful options may be:
1229
+
1230
+ * ``sep=""`` to append directly the prefix/unit to the value;
1231
+ * ``sep="\\ u2009"`` to use a thin space;
1232
+ * ``sep="\\ u202f"`` to use a narrow no-break space;
1233
+ * ``sep="\\ u00a0"`` to use a no-break space.
1239
1234
"""
1240
1235
self .unit = unit
1241
1236
self .places = places
@@ -1244,7 +1239,8 @@ def __init__(self, unit="", places=None, sep=" "):
1244
1239
def __call__ (self , x , pos = None ):
1245
1240
s = "%s%s" % (self .format_eng (x ), self .unit )
1246
1241
# Remove the trailing separator when there is neither prefix nor unit
1247
- s = s .strip (self .sep )
1242
+ if len (self .sep ) > 0 and s .endswith (self .sep ):
1243
+ s = s [:- len (self .sep )]
1248
1244
return self .fix_minus (s )
1249
1245
1250
1246
def format_eng (self , num ):
0 commit comments