← Back to home

Measurement formatting

Display a pressure measurement in different formats and SI prefixes, then propagate its uncertainty through a calculation. Prefixes affect display only: the stored value remains in pascals.

Download the Python source.

"""Demonstrate measurement formatting and display-only units."""

from labplotlib import Measurement


def main() -> None:
    pressure = Measurement.from_pm(2_000_000, 100_000)
    print("Automatic:", pressure)
    print("Raw:", pressure.to_string(format="raw"))
    print("Scientific:", pressure.to_string(format="scientific"))

    print("Display in MPa:", pressure.to_string(unit="Pa", prefix="mega"))
    print("Display in kPa:", pressure.to_string(unit="Pa", prefix="kilo"))
    print("Stored value in Pa:", pressure.value)

    doubled = pressure * 2
    print("Arithmetic result:", doubled.to_string(unit="Pa", prefix="mega"))


if __name__ == "__main__":
    main()

The final result is 4.0 ± 0.2 MPa. The published 0.6.0 package accepts units and prefixes in to_string; it does not support set_unit or decimals, which are currently described in the measurement reference.