Formatter

Formatter(formatter, *args, date=False, index=False, **kwargs)[source]

Return a Formatter instance. This function is used to interpret the xformatter, xformatter_kw, yformatter, and yformatter_kw arguments when passed to format, and the formatter and formatter_kw arguments when passed to colorbar methods wrapped by colorbar_wrapper.

Parameters
  • formatter (Formatter, str, list of str, or function) – The axis formatter specification, interpreted as follows:

    • If a Formatter instance already, the input argument is simply returned.

    • If list of strings, the ticks are labeled with these strings. Returns a FixedFormatter if index is False or an IndexFormatter if index is True.

    • If a function, the labels will be generated using this function. Returns a FuncFormatter.

    • If a string containing {x} or {x:...}, ticks will be formatted by calling string.format(x=number).

    • If a string containing '%' and date is False, ticks will be formatted using the C-style string % number method. See this page for a review. Returns a FormatStrFormatter.

    • If a string containing '%' and date is True, datetime string % number` formatting is used. See this page for a review. Returns a DateFormatter.

    Otherwise, formatter should be a string corresponding to one of the “registered” formatters or formatter presets (see below table). If formatter is a list or tuple and the first element is a “registered” formatter name, subsequent elements are passed to the formatter class as positional arguments.

    Key

    Class

    Description

    'null', 'none'

    NullFormatter

    No tick labels

    'auto'

    AutoFormatter

    New default tick labels for axes

    'sci'

    SciFormatter

    Format ticks with scientific notation.

    'simple'

    SimpleFormatter

    New default tick labels for e.g. contour labels

    'sigfig'

    SigFigFormatter

    Format labels using the first N significant digits

    'frac'

    FracFormatter

    Rational fractions

    'date'

    AutoDateFormatter

    Default tick labels for datetime axes

    'concise'

    ConciseDateFormatter

    More concise date labels introduced in matplotlib 3.1

    'datestr'

    DateFormatter

    Date formatting with C-style string % format notation

    'eng'

    EngFormatter

    Engineering notation

    'fixed'

    FixedFormatter

    List of strings

    'formatstr'

    FormatStrFormatter

    From C-style string % format notation

    'func'

    FuncFormatter

    Use an arbitrary function

    'index'

    IndexFormatter

    List of strings corresponding to non-negative integer positions

    'log'

    LogFormatterSciNotation

    For log-scale axes with scientific notation

    'logit'

    LogitFormatter

    For logistic-scale axes

    'percent'

    PercentFormatter

    Trailing percent sign

    'scalar'

    ScalarFormatter

    Old default tick labels for axes

    'strmethod'

    StrMethodFormatter

    From the string.format method

    'theta'

    ThetaFormatter

    Formats radians as degrees, with a degree symbol

    'e'

    FracFormatter preset

    Fractions of e

    'pi'

    FracFormatter preset

    Fractions of \(\pi\)

    'tau'

    FracFormatter preset

    Fractions of the one true circle constant \(\tau\)

    'lat'

    AutoFormatter preset

    Cardinal “SN” indicator

    'lon'

    AutoFormatter preset

    Cardinal “WE” indicator

    'deg'

    AutoFormatter preset

    Trailing degree symbol

    'deglat'

    AutoFormatter preset

    Trailing degree symbol and cardinal “SN” indicator

    'deglon'

    AutoFormatter preset

    Trailing degree symbol and cardinal “WE” indicator

    'dms'

    _PlateCarreeFormatter

    Labels with degree/minute/second support

    'dmslon'

    LongitudeFormatter

    Longitude labels with degree/minute/second support

    'dmslat'

    LatitudeFormatter

    Latitude labels with degree/minute/second support

  • date (bool, optional) – Toggles the behavior when formatter contains a '%' sign (see above).

  • index (bool, optional) – Controls the behavior when formatter is a list of strings (see above).

Other Parameters

*args, **kwargs – Passed to the Formatter class.

Returns

Formatter – A Formatter instance.