# toyplot.units module¶

Functionality for performing unit conversions.

toyplot.units.convert(value, target, default=None, reference=None)[source]

Convert quantities using real-world units.

Supported unit abbreviations include: centimeter, centimeters, cm, decimeter, decimeters, dm, in, inch, inches, m, meter, meters, mm, millimeter, millimeters, pc, pica, picas, point, points, pt, pixel, pixels, and px.

Relative quantities can be specified using %.

Parameters: value (number, string or (number, string) tuple) – Value to be converted. The value may be a number (in which case the default parameter must specify the default unit of measure), a string containing a number and unit abbreviation, or a (value, units) tuple. target (string) – Unit of measure to convert to. default (optional string) – Default unit of measure to use when value is a plain number, or when reference has been specified. reference (optional number) – When the caller specifies a relative measure using % as the unit abbreviation, the returned value will equal value * 0.01 * reference. Note that the reference must be specified in target units. Returns value converted to the target units, as a floating point number.