sycan.plot_util¶
Plot / readout helpers.
Lives separately from the plot-emitting modules (svg_util.bode_svg,
the autodraw labels, the REPL examples) so anything that needs to
print a number nicely can pull from one place. The heavy lifter is
fmt(), an engineering-notation formatter modelled on
matplotlib.ticker.EngFormatter but written in plain Python so the
package never grows a matplotlib runtime dependency just to label
microamps and megahertz consistently.
Functions
|
Engineering-notation formatter, matplotlib |
- sycan.plot_util.fmt(value, unit='', *, places=3, sep=' ', sign=False)[source]¶
Engineering-notation formatter, matplotlib
EngFormatter-style.Scales
valueso the mantissa sits in[1, 1000)and emits<mantissa><sep><SI prefix><unit>.placesis the number of significant digits in the mantissa — picked over matplotlib’s “decimal places after the point” because that’s what bias-point / measurement readouts actually want (900 mVinstead of0.900 Vregardless of how big the original number was).- Parameters:
value – Number to format.
int/float/ anythingfloat()accepts. NaN and ±inf pass through verbatim.unit (str) – Unit suffix appended after the SI prefix (
"V","Hz","Ω", …). Default"".places (int) – Significant digits in the mantissa. Default
3.sep (str) – Separator between the mantissa and the prefix+unit. Default
" ".sign (bool) – If True, positive values get a leading
"+". DefaultFalse.
- Return type:
str
Examples
>>> fmt(0.9, "V") '900 mV' >>> fmt(4.05e-5, "A") '40.5 µA' >>> fmt(2.5e9, "Hz") '2.50 GHz' >>> fmt(0, "V") '0 V' >>> fmt(-1.234, "V", sign=True) '-1.23 V' >>> fmt(1.5, "") '1.50'