toyplot.format module¶
Strategy objects for formatting text.
-
class
toyplot.format.
BasicFormatter
(nanshow=True)[source]¶ Bases:
toyplot.format.Formatter
Convert data to its default string representation.
-
format
(value)[source]¶ Return a text representation of the given value.
Parameters: value (value to be formatted) – Returns: - prefix (string) – Formatted data to be displayed before the separator.
- separator (string) – Separator between formatted data, or empty string.
- suffix (string) – Formatted data to be displayed after the separator, or empty string.
-
-
class
toyplot.format.
CurrencyFormatter
(format='{:, .2f}', nanshow=True, curr='cad', sep=', ', dp='.')[source]¶ Bases:
toyplot.format.BasicFormatter
Formats currency value with corresponding codes
Parameters: - places (required number of places after the decimal point) –
- curr (optional currency symbol before the sign (may be blank)) –
- sep (optional grouping separator (comma, period, space, or blank)) –
- dp (decimal point indicator (comma or period) only specify as blank when places is zero) –
-
format
(value)[source]¶ Return a text representation of the given currency value.
Parameters: value (value to be formatted) – Returns: - codes (string) – Formatted currency code to be displayed before the prefix, or empty string.
- prefix (string) – Formatted data to be displayed before the separator.
- dp (string) – Separator between formatted data, or empty string.
- suffix (string) – Formatted data to be displayed after the separator, or empty string.
-
class
toyplot.format.
FloatFormatter
(format='{:.6g}', nanshow=True)[source]¶ Bases:
toyplot.format.BasicFormatter
Formats floating-point values with aligned decimal points.
Parameters: - format (format string, optional) – Uses standard Python Format String Syntax.
- nanshow (bool, optional) – Set to False to hide NaN values.
-
format
(value)[source]¶ Return a text representation of the given value.
Parameters: value (value to be formatted) – Returns: - prefix (string) – Formatted data to be displayed before the separator.
- separator (string) – Separator between formatted data, or empty string.
- suffix (string) – Formatted data to be displayed after the separator, or empty string.
-
class
toyplot.format.
Formatter
[source]¶ Bases:
object
Abstract interface for formatters - objects that compute text representations from data.
-
format
(value)[source]¶ Return a text representation of the given value.
Parameters: value (value to be formatted) – Returns: - prefix (string) – Formatted data to be displayed before the separator.
- separator (string) – Separator between formatted data, or empty string.
- suffix (string) – Formatted data to be displayed after the separator, or empty string.
-
-
class
toyplot.format.
NullFormatter
[source]¶ Bases:
toyplot.format.Formatter
Do-nothing formatter that returns empty strings.
-
format
(value)[source]¶ Return a text representation of the given value.
Parameters: value (value to be formatted) – Returns: - prefix (string) – Formatted data to be displayed before the separator.
- separator (string) – Separator between formatted data, or empty string.
- suffix (string) – Formatted data to be displayed after the separator, or empty string.
-
-
class
toyplot.format.
UnitFormatter
(format='{:.6g}', nanshow=True, units='pt')[source]¶ Bases:
toyplot.format.BasicFormatter
Formats values with corresponding units
Parameters: - format (format string, optional) – Uses standard Python Format String Syntax.
- nanshow (bool, optional) – Set to False to hide NaN values.
-
format
(value)[source]¶ Return a text representation of the given value.
Parameters: - value (value to be formatted) –
- units (units to be formatted) –
Returns: - prefix (string) – Formatted data to be displayed before the separator.
- separator (string) – Separator between formatted data, or empty string.
- suffix (string) – Formatted data to be displayed after the separator, or empty string.
- units (string) – Formatted units to be displayed after the suffix, or empty string.