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

fmt(value[, unit, places, sep, sign])

Engineering-notation formatter, matplotlib EngFormatter-style.

sycan.plot_util.fmt(value, unit='', *, places=3, sep=' ', sign=False)[source]

Engineering-notation formatter, matplotlib EngFormatter-style.

Scales value so the mantissa sits in [1, 1000) and emits <mantissa><sep><SI prefix><unit>. places is 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 mV instead of 0.900 V regardless of how big the original number was).

Parameters:
  • value – Number to format. int / float / anything float() 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 "+". Default False.

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'