Formatter¶
- Formatter(formatter, *args, date=False, index=False, **kwargs)[source]¶
Return a
Formatter
instance.- Parameters
formatter (
Formatter
,str
,list
ofstr
,callable()
, ortuple
) – The 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
ifindex
isFalse
or anIndexFormatter
ifindex
isTrue
.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 callingstring.format(x=number)
. Returns aStrMethodFormatter
.If a string containing
'%'
anddate
isFalse
, ticks will be formatted using the C-stylestring % number
method. See this page for a review. Returns aFormatStrFormatter
.If a string containing
'%'
anddate
isTrue
, datetimestring % number`
formatting is used. See this page for a review. Returns aDateFormatter
.
Otherwise,
formatter
should be a string corresponding to one of the “registered” formatters or formatter presets (see below table). Ifformatter
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. For example,pplt.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
N
significant 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 % format
notation'eng'
Engineering notation
'fixed'
List of strings
'formatstr'
From C-style
string % format
notation'func'
Use an arbitrary function
'index'
IndexFormatter
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.format
method'theta'
Formats radians as degrees, with a degree symbol
'e'
FracFormatter
presetFractions of e
'pi'
FracFormatter
presetFractions of \(\pi\)
'tau'
FracFormatter
presetFractions of the one true circle constant \(\tau\)
'lat'
AutoFormatter
presetCardinal “SN” indicator
'lon'
AutoFormatter
presetCardinal “WE” indicator
'deg'
AutoFormatter
presetTrailing degree symbol
'deglat'
AutoFormatter
presetTrailing degree symbol and cardinal “SN” indicator
'deglon'
AutoFormatter
presetTrailing degree symbol and cardinal “WE” indicator
'dms'
_PlateCarreeFormatter
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
formatter
contains a'%'
sign (see above).- indexbool, optional
Controls the behavior when
formatter
is a list of strings (see above).