AutoFormatter

class AutoFormatter(zerotrim=None, tickrange=None, wraprange=None, prefix=None, suffix=None, negpos=None, **kwargs)[source]

Bases: matplotlib.ticker.ScalarFormatter

The new default formatter. Differs from ScalarFormatter in the following ways:

  1. Trims trailing decimal zeros by default.

  2. Permits specifying range within which major tick marks are labeled.

  3. Permits adding arbitrary prefix or suffix to every tick label string.

  4. Permits adding “negative” and “positive” indicator.

Parameters
  • zerotrim (bool, optional) – Whether to trim trailing zeros. Default is rc[‘formatter.zerotrim’] = True.

  • tickrange ((float, float), optional) – Range within which major tick marks are labelled. Default is (-np.inf, np.inf).

  • wraprange ((float, float), optional) – Range outside of which tick values are wrapped. For example, (0, 2) will format a value of 2.5 as 0.5, and (-180, 180) will format a value of 200 as -180 + 20 == -160.

  • prefix, suffix (str, optional) – Prefix and suffix for all tick strings.

  • negpos (str, optional) – Length-2 string indicating the suffix for “negative” and “positive” numbers, meant to replace the minus sign.

Other Parameters

**kwargs – Passed to ScalarFormatter.

Warning

The matplotlib ScalarFormatter determines the number of significant digits based on the axis limits, and therefore may truncate digits while formatting ticks on highly non-linear axis scales like LogScale. We try to correct this behavior with a patch.

Methods Summary

__call__(x[, pos])

Convert number to a string.

get_offset()

Get the offset but always use math text.