Formatter
- Formatter(formatter, *args, date=False, index=False, **kwargs)[source]
Return a
Formatterinstance.- Parameters:
formatter (
Formatter,str,bool,callable(), or sequence) – The formatter specification, interpreted as follows:If a
Formatterinstance already, acopy.copyof the instance is returned.If
False, aNullFormatteris used, and ifTrue, the defaultAutoFormatteris used.If a function, the labels will be generated using this function. Returns a
FuncFormatter.If sequence of strings, the ticks are labeled with these strings. Returns a
FixedFormatterby default or anIndexFormatterifindexisTrue.If a string containing
{x}or{x:...}, ticks will be formatted by callingstring.format(x=number). Returns aStrMethodFormatter.If a string containing
'%'anddateisFalse, ticks will be formatted using the C-stylestring % numbermethod. See this page for a review. Returns aFormatStrFormatter.If a string containing
'%'anddateisTrue, ticks will be formatted usingstrfrtime. See this page for a review. Returns aDateFormatter.
Otherwise,
formattershould be a string corresponding to one of the “registered” formatters or formatter presets (see below table). Ifformatteris a list or tuple and the first element is a “registered” formatter name, subsequent elements are passed to the formatter class as positional arguments. For example,uplt.Formatter(('sigfig', 3))is equivalent toFormatter('sigfig', 3).Key
Class
Description
'null','none'No tick labels
'auto'New default tick labels for axes
'sci'Format ticks with scientific notation
'simple'New default tick labels for e.g. contour labels
'sigfig'Format labels using the first
Nsignificant digits'frac'Rational fractions
'date'Default tick labels for datetime axes
'concise'More concise date labels introduced in matplotlib 3.1
'datestr'Date formatting with C-style
string % formatnotation'eng'Engineering notation
'fixed'List of strings
'formatstr'From C-style
string % formatnotation'func'Use an arbitrary function
'index'List of strings corresponding to non-negative integer positions
'log'For log-scale axes with scientific notation
'logit'For logistic-scale axes
'percent'Trailing percent sign
'scalar'The default matplotlib formatter
'strmethod'From the
string.formatmethod'theta'Formats radians as degrees, with a degree symbol
'e'FracFormatterpresetFractions of e
'pi'FracFormatterpresetFractions of \(\pi\)
'tau'FracFormatterpresetFractions of the one true circle constant \(\tau\)
'lat'AutoFormatterpresetCardinal “SN” indicator
'lon'AutoFormatterpresetCardinal “WE” indicator
'deg'AutoFormatterpresetTrailing degree symbol
'deglat'AutoFormatterpresetTrailing degree symbol and cardinal “SN” indicator
'deglon'AutoFormatterpresetTrailing degree symbol and cardinal “WE” indicator
'dms'Labels with degree/minute/second support
'dmslon'Longitude labels with degree/minute/second support
'dmslat'Latitude labels with degree/minute/second support
- datebool, optional
Toggles the behavior when
formattercontains a'%'sign (see above).- indexbool, optional
Controls the behavior when
formatteris a sequence of strings (see above).
- Other Parameters:
*args, **kwargs – Passed to the
Formatterclass.- Returns:
matplotlib.ticker.Formatter– AFormatterinstance.