Formatter¶
-
Formatter
(formatter, *args, date=False, index=False, **kwargs)[source]¶ Returns a
Formatter
instance, 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
'datestr'
Date formatting with C-style
string % format
notation'concise'
More concise date labels introduced in matplotlib 3.1
'scalar'
Old default tick labels for axes
'strmethod'
From the
string.format
method'formatstr'
From C-style
string % format
notation'log'
,'sci'
For log-scale axes with scientific notation
'math'
For log-scale axes with math text
'logit'
For logistic-scale axes
'eng'
Engineering notation
'percent'
Trailing percent sign
'fixed'
List of strings
'index'
List of strings corresponding to non-negative integer positions along the axis
'theta'
Formats radians as degrees, with a degree symbol
'pi'
FracFormatter
presetFractions of \(\pi\)
'e'
FracFormatter
presetFractions of e
'deg'
SimpleFormatter
presetTrailing degree symbol
'deglon'
SimpleFormatter
presetTrailing degree symbol and cardinal “WE” indicator
'deglat'
SimpleFormatter
presetTrailing degree symbol and cardinal “SN” indicator
'lon'
SimpleFormatter
presetCardinal “WE” indicator
'lat'
SimpleFormatter
presetCardinal “SN” 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