@@ -1184,19 +1184,8 @@ class EngFormatter(Formatter):
11841184 """
11851185 Formats axis values using engineering prefixes to represent powers
11861186 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 "".
11991187 """
1188+
12001189 # The SI engineering prefixes
12011190 ENG_PREFIXES = {
12021191 - 24 : "y" ,
@@ -1222,20 +1211,26 @@ def __init__(self, unit="", places=None, sep=" "):
12221211 """
12231212 Parameters
12241213 ----------
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- 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.
12391234 """
12401235 self .unit = unit
12411236 self .places = places
@@ -1244,7 +1239,8 @@ def __init__(self, unit="", places=None, sep=" "):
12441239 def __call__ (self , x , pos = None ):
12451240 s = "%s%s" % (self .format_eng (x ), self .unit )
12461241 # 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 )]
12481244 return self .fix_minus (s )
12491245
12501246 def format_eng (self , num ):
0 commit comments