Formatter¶
-
Formatter
(formatter, *args, date=False, index=False, **kwargs)[source]¶ Return a
Formatter
instance. This function is used to interpret thexformatter
,xformatter_kw
,yformatter
, andyformatter_kw
arguments when passed toformat
, and theformatter
andformatter_kw
arguments when passed to colorbar methods wrapped bycolorbar_wrapper
.- Parameters
formatter (
Formatter
, str, list of str, or function) – IfFormatter
, the object is returned.If list of strings, ticks are labeled with these strings. Returns a
FixedFormatter
instance whenindex
isFalse
and anIndexFormatter
instance whenindex
isTrue
.If function, labels will be generated using this function. Returns a
FuncFormatter
instance.If string, there are 4 possibilities:
If string contains
'%'
anddate
isFalse
, ticks will be formatted using the C-notationstring % number
method. See this page for a review.If string contains
'%'
anddate
isTrue
, datetimestring % number
formatting is used. See this page for a review.If string contains
{x}
or{x:...}
, ticks will be formatted by callingstring.format(x=number)
.In all other cases, a dictionary lookup is performed (see below table).
Key
Class
Description
'null'
,'none'
No tick labels
'auto'
New default tick labels for axes
'simple'
New default tick labels for e.g. contour labels
'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 % format
notation'eng'
Engineering notation
'fixed'
List of strings
'formatstr'
From C-style
string % format
notation'index'
List of strings corresponding to non-negative integer positions along the axis
'log'
,'sci'
For log-scale axes with scientific notation
'logit'
For logistic-scale axes
'math'
For log-scale axes with math text
'percent'
Trailing percent sign
'scalar'
Old default tick labels for axes
'strmethod'
From the
string.format
method'theta'
Formats radians as degrees, with a degree symbol
'e'
FracFormatter
presetFractions of e
'pi'
FracFormatter
presetFractions of \(\pi\)
'deg'
AutoFormatter
presetTrailing degree symbol
'deglat'
AutoFormatter
presetTrailing degree symbol and cardinal “SN” indicator
'deglon'
AutoFormatter
presetTrailing degree symbol and cardinal “WE” indicator
'lat'
AutoFormatter
presetCardinal “SN” indicator
'lon'
AutoFormatter
presetCardinal “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