Tick formatters¶
A Formatter turns a tick's numeric position into its label string. Pass one to
Axes.set(xformatter=..., yformatter=...) or to Figure.colorbar(format=...);
a "{x:.2f}" template string or any callable is accepted in the same places.
ticker
¶
Tick-label formatters.
A Formatter turns a tick's numeric position into its label string. Pass
an instance to Axes.set via xformatter=/yformatter= (or
to a colorbar); the active Scale locates the tick
positions and the formatter decides how each is written. Labels may contain
$...$ math (e.g. LogFormatter emits $10^{k}$), which flows
through the same editable-text pipeline as every other label.
Formatters that render a number sign it with MINUS (see
fix_minus). The ones that hand back a string you supplied -
FixedFormatter, FuncFormatter, StrMethodFormatter,
DateFormatter - pass it through untouched, so "%Y-%m-%d" keeps its
hyphens.
Formatter
¶
Base formatter: subclasses implement __call__. Calling a formatter
with a tick value (and optional integer position) returns its label.
format_ticks
¶
Label a whole sequence of tick positions (some formatters use the set, e.g. to choose a shared offset/exponent).
ScalarFormatter
¶
Bases: Formatter
Plain decimal formatting. With scientific=True values outside
10**-power_limits[0] .. 10**power_limits[1] render in $m×10^{k}$
mantissa/exponent form.
Source code in python/pyplotrs/ticker.py
FixedFormatter
¶
FuncFormatter
¶
StrMethodFormatter
¶
PercentFormatter
¶
Bases: Formatter
Format as a percentage: value / xmax * 100 with symbol appended.
decimals=None auto-picks a sensible precision.
Source code in python/pyplotrs/ticker.py
EngFormatter
¶
Bases: Formatter
Engineering notation: scale by a power of 1000 and append an SI prefix
(k, M, m, µ …), then unit.
Source code in python/pyplotrs/ticker.py
LogFormatter
¶
Bases: Formatter
Label decades as $10^{k}$ math; non-decade ticks get "" (unless
label_minor is set, which writes them plainly).
Source code in python/pyplotrs/ticker.py
DateFormatter
¶
Bases: Formatter
Format a day-number tick (see pyplotrs.scales.date2num) with a
strftime pattern, e.g. DateFormatter("%Y-%m").
Source code in python/pyplotrs/ticker.py
get
¶
Resolve a formatter argument: a Formatter, a str format
template ("{x:.2f}"), a callable, or None.
Source code in python/pyplotrs/ticker.py
fix_minus
¶
Replace the sign in a numeric label with a real MINUS.
Only apply this to strings pyplotrs formatted from a number - never to user
text, category names, or strftime output, where a hyphen is a hyphen.
Math ($...$) is likewise left alone: the math engine maps - to
U+2212 itself, and feeding it a pre-substituted glyph would lose the binary
operator's spacing. Disabled by pyplotrs.set_unicode_minus.