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) – If Formatter, the object is returned.

    If list of strings, ticks are labeled with these strings. Returns a FixedFormatter instance when index is False and an IndexFormatter instance when index is True.

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

    If string, there are 4 possibilities:

    1. If string contains '%' and date is False, ticks will be formatted using the C-notation string % number method. See this page for a review.

    2. If string contains '%' and date is True, datetime string % number formatting is used. See this page for a review.

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

    4. In all other cases, a dictionary lookup is performed (see below table).

    Key

    Class

    Description

    'null', 'none'

    NullFormatter

    No tick labels

    'auto'

    AutoFormatter

    New default tick labels for axes

    'simple'

    SimpleFormatter

    New default tick labels for e.g. contour labels

    '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

    'index'

    IndexFormatter

    List of strings corresponding to non-negative integer positions along the axis

    'log', 'sci'

    LogFormatterSciNotation

    For log-scale axes with scientific notation

    'logit'

    LogitFormatter

    For logistic-scale axes

    'math'

    LogFormatterMathtext

    For log-scale axes with math text

    '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\)

    '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

    'lat'

    AutoFormatter preset

    Cardinal “SN” indicator

    'lon'

    AutoFormatter preset

    Cardinal “WE” indicator

  • 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).

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

Returns

Formatter – A Formatter instance.