matplotlib.ticker
#
Tick locating and formatting#
This module contains classes for configuring tick locating and formatting.Generic tick locators and formatters are provided, as well as domain specificcustom ones.
Although the locators know nothing about major or minor ticks, they are usedby the Axis class to support major and minor tick locating and formatting.
Tick locating#
The Locator class is the base class for all tick locators. The locatorshandle autoscaling of the view limits based on the data limits, and thechoosing of tick locations. A useful semi-automatic tick locator isMultipleLocator
. It is initialized with a base, e.g., 10, and it picksaxis limits and ticks that are multiples of that base.
The Locator subclasses defined here are:
| |
Finds up to a max number of intervals with ticks atnice locations. | |
Space ticks evenly from min to max. | |
Space ticks logarithmically from min to max. | |
Ticks and range are a multiple of base; either integeror float. | |
Tick locations are fixed. | |
Locator for index plots (e.g., where | |
No ticks. | |
Locator for use with the symlog norm; works like | |
Locator for use with the asinh norm, attempting tospace ticks approximately uniformly. | |
Locator for logit scaling. | |
Locator for minor ticks when the axis is linear and themajor ticks are uniformly spaced. Subdivides the majortick interval into a specified number of minorintervals, defaulting to 4 or 5 depending on the majorinterval. |
There are a number of locators specialized for date locations - seethedates
module.
You can define your own locator by deriving from Locator. You mustoverride the__call__
method, which returns a sequence of locations,and you will probably want to override the autoscale method to set theview limits from the data limits.
If you want to override the default locator, use one of the above or a customlocator and pass it to the x- or y-axis instance. The relevant methods are:
ax.xaxis.set_major_locator(xmajor_locator)ax.xaxis.set_minor_locator(xminor_locator)ax.yaxis.set_major_locator(ymajor_locator)ax.yaxis.set_minor_locator(yminor_locator)
The default minor locator isNullLocator
, i.e., no minor ticks on by default.
Note
Locator
instances should not be used with more than oneAxis
orAxes
. So instead of:
locator=MultipleLocator(5)ax.xaxis.set_major_locator(locator)ax2.xaxis.set_major_locator(locator)
do the following instead:
ax.xaxis.set_major_locator(MultipleLocator(5))ax2.xaxis.set_major_locator(MultipleLocator(5))
Tick formatting#
Tick formatting is controlled by classes derived from Formatter. The formatteroperates on a single tick value and returns a string to the axis.
No labels on the ticks. | |
Set the strings manually for the labels. | |
User defined function sets the labels. | |
Use string | |
Use an old-style sprintf format string. | |
Default formatter for scalars: autopick the formatstring. | |
Formatter for log axes. | |
Format values for log axis using | |
Format values for log axis using | |
Format values for log axis using scientific notation. | |
Probability formatter. | |
Format labels in engineering notation. | |
Format labels as a percentage. |
You can derive your own formatter from the Formatter base class bysimply overriding the__call__
method. The formatter class hasaccess to the axis view and data limits.
To control the major and minor tick label formats, use one of thefollowing methods:
ax.xaxis.set_major_formatter(xmajor_formatter)ax.xaxis.set_minor_formatter(xminor_formatter)ax.yaxis.set_major_formatter(ymajor_formatter)ax.yaxis.set_minor_formatter(yminor_formatter)
In addition to aFormatter
instance,set_major_formatter
andset_minor_formatter
also accept astr
or function.str
inputwill be internally replaced with an autogeneratedStrMethodFormatter
withthe inputstr
. For function input, aFuncFormatter
with the inputfunction will be generated and used.
SeeMajor and minor ticks for an example of setting majorand minor ticks. See thematplotlib.dates
module for more informationand examples of using date locators and formatters.
- classmatplotlib.ticker.AsinhLocator(linear_width,numticks=11,symthresh=0.2,base=10,subs=None)[source]#
Bases:
Locator
Place ticks spaced evenly on an inverse-sinh scale.
Generally used with the
AsinhScale
class.Note
This API is provisional and may be revised in the futurebased on early user feedback.
- Parameters:
- linear_widthfloat
The scale parameter defining the extentof the quasi-linear region.
- numticksint, default: 11
The approximate number of major ticks that will fitalong the entire axis
- symthreshfloat, default: 0.2
The fractional threshold beneath which data which coversa range that is approximately symmetric about zerowill have ticks that are exactly symmetric.
- baseint, default: 10
The number base used for rounding tick locationson a logarithmic scale. If this is less than one,then rounding is to the nearest integer multipleof powers of ten.
- substuple, default: None
Multiples of the number base, typically usedfor the minor ticks, e.g. (2, 5) when base=10.
- classmatplotlib.ticker.AutoLocator[source]#
Bases:
MaxNLocator
Place evenly spaced ticks, with the step size and maximum number of ticks chosenautomatically.
This is a subclass of
MaxNLocator
, with parametersnbins = 'auto' andsteps = [1, 2, 2.5, 5, 10].To know the values of the non-public parameters, please have alook to the defaults of
MaxNLocator
.
- classmatplotlib.ticker.AutoMinorLocator(n=None)[source]#
Bases:
Locator
Place evenly spaced minor ticks, with the step size and maximum number of tickschosen automatically.
The Axis must use a linear scale and have evenly spaced major ticks.
- Parameters:
- nint or 'auto', default:
rcParams["xtick.minor.ndivs"]
(default:'auto'
) orrcParams["ytick.minor.ndivs"]
(default:'auto'
) The number of subdivisions of the interval between major ticks;e.g., n=2 will place a single minor tick midway between major ticks.
Ifn is 'auto', it will be set to 4 or 5: if the distancebetween the major ticks equals 1, 2.5, 5 or 10 it can be perfectlydivided in 5 equidistant sub-intervals with a length multiple of0.05; otherwise, it is divided in 4 sub-intervals.
- nint or 'auto', default:
- classmatplotlib.ticker.EngFormatter(unit='',places=None,sep='',*,usetex=None,useMathText=None,useOffset=False)[source]#
Bases:
ScalarFormatter
Format axis values using engineering prefixes to represent powersof 1000, plus a specified unit, e.g., 10 MHz instead of 1e7.
- Parameters:
- unitstr, default: ""
Unit symbol to use, suitable for use with single-letterrepresentations of powers of 1000. For example, 'Hz' or 'm'.
- placesint, default: None
Precision with which to display the number, specified indigits after the decimal point (there will be between oneand three digits before the decimal point). If it is None,the formatting falls back to the floating point format '%g',which displays up to 6significant digits, i.e. the equivalentvalue forplaces varies between 0 and 5 (inclusive).
- sepstr, default: " "
Separator used between the value and the prefix/unit. Forexample, one get '3.14 mV' if
sep
is " " (default) and'3.14mV' ifsep
is "". Besides the default behavior, someother useful options may be:sep=""
to append directly the prefix/unit to the value;sep="\N{THINSPACE}"
(U+2009
);sep="\N{NARROWNO-BREAKSPACE}"
(U+202F
);sep="\N{NO-BREAKSPACE}"
(U+00A0
).
- usetexbool, default:
rcParams["text.usetex"]
(default:False
) To enable/disable the use of TeX's math mode for rendering thenumbers in the formatter.
- useMathTextbool, default:
rcParams["axes.formatter.use_mathtext"]
(default:False
) To enable/disable the use mathtext for rendering the numbers inthe formatter.
- useOffsetbool or float, default: False
Whether to use offset notation with\(10^{3*N}\) based prefixes.This features allows showing an offset with standard SI order ofmagnitude prefix near the axis. Offset is computed similarly tohow
ScalarFormatter
computes it internally, but here you areguaranteed to get an offset which will make the tick labels exceed3 digits. See alsoset_useOffset
.Added in version 3.10.
- ENG_PREFIXES={-30:'q',-27:'r',-24:'y',-21:'z',-18:'a',-15:'f',-12:'p',-9:'n',-6:'µ',-3:'m',0:'',3:'k',6:'M',9:'G',12:'T',15:'P',18:'E',21:'Z',24:'Y',27:'R',30:'Q'}#
- classmatplotlib.ticker.FixedFormatter(seq)[source]#
Bases:
Formatter
Return fixed strings for tick labels based only on position, not value.
Note
FixedFormatter
should only be used together withFixedLocator
.Otherwise, the labels may end up in unexpected positions.Set the sequenceseq of strings that will be used for labels.
- classmatplotlib.ticker.FixedLocator(locs,nbins=None)[source]#
Bases:
Locator
Place ticks at a set of fixed values.
Ifnbins is None ticks are placed at all values. Otherwise, thelocs array ofpossible positions will be subsampled to keep the number of ticks\(\leq nbins + 1\). The subsampling will be done to include the smallestabsolute value; for example, if zero is included in the array of possibilities, thenit will be included in the chosen ticks.
- classmatplotlib.ticker.FormatStrFormatter(fmt)[source]#
Bases:
Formatter
Use an old-style ('%' operator) format string to format the tick.
The format string should have a single variable format (%) in it.It will be applied to the value (not the position) of the tick.
Negative numeric values (e.g., -1) will use a dash, not a Unicode minus;use mathtext to get a Unicode minus by wrapping the format specifier with $(e.g. "$%g$").
- classmatplotlib.ticker.Formatter[source]#
Bases:
TickHelper
Create a string based on a tick value and location.
- staticfix_minus(s)[source]#
Some classes may want to replace a hyphen for minus with the properUnicode symbol (U+2212) for typographical correctness. This is ahelper method to perform such a replacement when it is enabled via
rcParams["axes.unicode_minus"]
(default:True
).
- format_data(value)[source]#
Return the full string representation of the value with theposition unspecified.
- format_data_short(value)[source]#
Return a short string version of the tick value.
Defaults to the position-independent long value.
- locs=[]#
- classmatplotlib.ticker.FuncFormatter(func)[source]#
Bases:
Formatter
Use a user-defined function for formatting.
The function should take in two inputs (a tick value
x
and apositionpos
), and return a string containing the correspondingtick label.
- classmatplotlib.ticker.IndexLocator(base,offset)[source]#
Bases:
Locator
Place ticks at every nth point plotted.
IndexLocator assumes index plotting; i.e., that the ticks are placed at integervalues in the range between 0 and len(data) inclusive.
Place ticks everybase data point, starting atoffset.
- classmatplotlib.ticker.LinearLocator(numticks=None,presets=None)[source]#
Bases:
Locator
Place ticks at evenly spaced values.
The first time this function is called, it will try to set the number ofticks to make a nice tick partitioning. Thereafter, the number of tickswill be fixed to avoid jumping during interactive navigation.
- Parameters:
- numticksint or None, default None
Number of ticks. If None,numticks = 11.
- presetsdict or None, default: None
Dictionary mapping
(vmin,vmax)
to an array of locations.Overridesnumticks if there is an entry for the current(vmin,vmax)
.
- propertynumticks#
- classmatplotlib.ticker.Locator[source]#
Bases:
TickHelper
Determine tick locations.
Note that the same locator should not be used across multiple
Axis
because the locator stores references to the Axisdata and view limits.- MAXTICKS=1000#
- nonsingular(v0,v1)[source]#
Adjust a range as needed to avoid singularities.
This method gets called during autoscaling, with
(v0,v1)
set tothe data limits on the Axes if the Axes contains any data, or(-inf,+inf)
if not.If
v0==v1
(possibly up to some floating point slop), thismethod returns an expanded interval around this value.If
(v0,v1)==(-inf,+inf)
, this method returns appropriatedefault view limits.Otherwise,
(v0,v1)
is returned without modification.
- raise_if_exceeds(locs)[source]#
Log at WARNING level iflocs is longer than
Locator.MAXTICKS
.This is intended to be called immediately before returninglocs from
__call__
to inform users in case their Locator returns a hugenumber of ticks, causing Matplotlib to run out of memory.The "strange" name of this method dates back to when it would raise anexception instead of emitting a log.
- set_params(**kwargs)[source]#
Do nothing, and raise a warning. Any locator class not supporting theset_params() function will call this.
- classmatplotlib.ticker.LogFormatter(base=10.0,labelOnlyBase=False,minor_thresholds=None,linthresh=None)[source]#
Bases:
Formatter
Base class for formatting ticks on a log or symlog scale.
It may be instantiated directly, or subclassed.
- Parameters:
- basefloat, default: 10.
Base of the logarithm used in all calculations.
- labelOnlyBasebool, default: False
If True, label ticks only at integer powers of base.This is normally True for major ticks and False for minor ticks.
- minor_thresholds(subset, all), default: (1, 0.4)
If labelOnlyBase is False, these two numbers controlthe labeling of ticks that are not at integer powers ofbase; normally these are the minor ticks.
The first number (subset) is the largest number of major ticks forwhich minor ticks are labeled; e.g., the default, 1, means that minorticks are labeled as long as there is no more than 1 major tick. (Itis assumed that major ticks are at integer powers ofbase.)
The second number (all) is a threshold, in log-units of the axislimit range, over which only a subset of the minor ticks are labeled,so as to avoid crowding; e.g., with the default value (0.4) and theusual
base=10
, all minor ticks are shown only if the axis limitrange spans less than 0.4 decades.- linthreshNone or float, default: None
If a symmetric log scale is in use, its
linthresh
parameter must be supplied here.
Notes
The
set_locs
method must be called to enable the subsettinglogic controlled by theminor_thresholds
parameter.In some cases such as the colorbar, there is no distinction betweenmajor and minor ticks; the tick locations might be set manually,or by a locator that puts ticks at integer powers of base andat intermediate locations. For this situation, disable theminor_thresholds logic by using
minor_thresholds=(np.inf,np.inf)
,so that all ticks will be labeled.To disable labeling of minor ticks when 'labelOnlyBase' is False,use
minor_thresholds=(0,0)
. This is the default for the"classic" style.Examples
To label a subset of minor ticks when there are up to 2 major ticks,and all of the ticks when zoomed in to 0.5 decades or less, use
minor_thresholds=(2,0.5)
.- format_data(value)[source]#
Return the full string representation of the value with theposition unspecified.
- format_data_short(value)[source]#
Return a short string version of the tick value.
Defaults to the position-independent long value.
- set_base(base)[source]#
Change thebase for labeling.
Warning
Should always match the base used for
LogLocator
- classmatplotlib.ticker.LogFormatterExponent(base=10.0,labelOnlyBase=False,minor_thresholds=None,linthresh=None)[source]#
Bases:
LogFormatter
Format values for log axis using
exponent=log_base(value)
.
- classmatplotlib.ticker.LogFormatterMathtext(base=10.0,labelOnlyBase=False,minor_thresholds=None,linthresh=None)[source]#
Bases:
LogFormatter
Format values for log axis using
exponent=log_base(value)
.
- classmatplotlib.ticker.LogFormatterSciNotation(base=10.0,labelOnlyBase=False,minor_thresholds=None,linthresh=None)[source]#
Bases:
LogFormatterMathtext
Format values following scientific notation in a logarithmic axis.
- classmatplotlib.ticker.LogLocator(base=10.0,subs=(1.0,),*,numticks=None)[source]#
Bases:
Locator
Place logarithmically spaced ticks.
Places ticks at the values
subs[j]*base**i
.- Parameters:
- basefloat, default: 10.0
The base of the log used, so major ticks are placed at
base**n
, wheren
is an integer.- subsNone or {'auto', 'all'} or sequence of float, default: (1.0,)
Gives the multiples of integer powers of the base at which to place ticks.The default of
(1.0,)
places ticks only at integer powers of the base.Permitted string values are'auto'
and'all'
. Both of these use analgorithm based on the axis view limits to determine whether and how to putticks between integer powers of the base:-'auto'
: Ticks are placed only between integer powers.-'all'
: Ticks are placed betweenand at integer powers.-None
: Equivalent to'auto'
.- numticksNone or int, default: None
The maximum number of ticks to allow on a given axis. The default of
None
will try to choose intelligently as long as this Locator hasalready been assigned to an axis usingget_tick_space
, butotherwise falls back to 9.
- nonsingular(vmin,vmax)[source]#
Adjust a range as needed to avoid singularities.
This method gets called during autoscaling, with
(v0,v1)
set tothe data limits on the Axes if the Axes contains any data, or(-inf,+inf)
if not.If
v0==v1
(possibly up to some floating point slop), thismethod returns an expanded interval around this value.If
(v0,v1)==(-inf,+inf)
, this method returns appropriatedefault view limits.Otherwise,
(v0,v1)
is returned without modification.
- classmatplotlib.ticker.LogitFormatter(*,use_overline=False,one_half='\\frac{1}{2}',minor=False,minor_threshold=25,minor_number=6)[source]#
Bases:
Formatter
Probability formatter (using Math text).
- Parameters:
- use_overlinebool, default: False
If x > 1/2, with x = 1 - v, indicate if x should be displayed as$overline{v}$. The default is to display $1 - v$.
- one_halfstr, default: r"\frac{1}{2}"
The string used to represent 1/2.
- minorbool, default: False
Indicate if the formatter is formatting minor ticks or not.Basically minor ticks are not labelled, except when only few ticksare provided, ticks with most space with neighbor ticks arelabelled. See other parameters to change the default behavior.
- minor_thresholdint, default: 25
Maximum number of locs for labelling some minor ticks. Thisparameter have no effect if minor is False.
- minor_numberint, default: 6
Number of ticks which are labelled when the number of ticks isbelow the threshold.
- format_data_short(value)[source]#
Return a short string version of the tick value.
Defaults to the position-independent long value.
- set_locs(locs)[source]#
Set the locations of the ticks.
This method is called before computing the tick labels because someformatters need to know all tick locations to do so.
- set_minor_number(minor_number)[source]#
Set the number of minor ticks to label when some minor ticks arelabelled.
- Parameters:
- minor_numberint
Number of ticks which are labelled when the number of ticks isbelow the threshold.
- set_minor_threshold(minor_threshold)[source]#
Set the threshold for labelling minors ticks.
- Parameters:
- minor_thresholdint
Maximum number of locations for labelling some minor ticks. Thisparameter have no effect if minor is False.
- classmatplotlib.ticker.LogitLocator(minor=False,*,nbins='auto')[source]#
Bases:
MaxNLocator
Place ticks spaced evenly on a logit scale.
- Parameters:
- nbinsint or 'auto', optional
Number of ticks. Only used if minor is False.
- minorbool, default: False
Indicate if this locator is for minor ticks or not.
- propertyminor#
- nonsingular(vmin,vmax)[source]#
Adjust a range as needed to avoid singularities.
This method gets called during autoscaling, with
(v0,v1)
set tothe data limits on the Axes if the Axes contains any data, or(-inf,+inf)
if not.If
v0==v1
(possibly up to some floating point slop), thismethod returns an expanded interval around this value.If
(v0,v1)==(-inf,+inf)
, this method returns appropriatedefault view limits.Otherwise,
(v0,v1)
is returned without modification.
- classmatplotlib.ticker.MaxNLocator(nbins=None,**kwargs)[source]#
Bases:
Locator
Place evenly spaced ticks, with a cap on the total number of ticks.
Finds nice tick locations with no more than\(nbins + 1\) ticks being within theview limits. Locations beyond the limits are added to support autoscaling.
- Parameters:
- nbinsint or 'auto', default: 10
Maximum number of intervals; one less than max number ofticks. If the string 'auto', the number of bins will beautomatically determined based on the length of the axis.
- stepsarray-like, optional
Sequence of acceptable tick multiples, starting with 1 andending with 10. For example, if
steps=[1,2,4,5,10]
,20,40,60
or0.4,0.6,0.8
would be possiblesets of ticks because they are multiples of 2.30,60,90
would not be generated because 3 does notappear in this example list of steps.- integerbool, default: False
If True, ticks will take only integer values, provided at leastmin_n_ticks integers are found within the view limits.
- symmetricbool, default: False
If True, autoscaling will result in a range symmetric about zero.
- prune{'lower', 'upper', 'both', None}, default: None
Remove the 'lower' tick, the 'upper' tick, or ticks on 'both' sidesif they fall exactly on an axis' edge (this typically occurs when
rcParams["axes.autolimit_mode"]
(default:'data'
) is 'round_numbers'). Removing such ticksis mostly useful for stacked or ganged plots, where the upper tickof an Axes overlaps with the lower tick of the axes above it.- min_n_ticksint, default: 2
Relaxnbins andinteger constraints if necessary to obtainthis minimum number of ticks.
- default_params={'integer':False,'min_n_ticks':2,'nbins':10,'prune':None,'steps':None,'symmetric':False}#
- set_params(**kwargs)[source]#
Set parameters for this locator.
- Parameters:
- nbinsint or 'auto', optional
see
MaxNLocator
- stepsarray-like, optional
see
MaxNLocator
- integerbool, optional
see
MaxNLocator
- symmetricbool, optional
see
MaxNLocator
- prune{'lower', 'upper', 'both', None}, optional
see
MaxNLocator
- min_n_ticksint, optional
see
MaxNLocator
- classmatplotlib.ticker.MultipleLocator(base=1.0,offset=0.0)[source]#
Bases:
Locator
Place ticks at every integer multiple of a base plus an offset.
- Parameters:
- basefloat > 0, default: 1.0
Interval between ticks.
- offsetfloat, default: 0.0
Value added to each multiple ofbase.
Added in version 3.8.
- set_params(base=None,offset=None)[source]#
Set parameters within this locator.
- Parameters:
- basefloat > 0, optional
Interval between ticks.
- offsetfloat, optional
Value added to each multiple ofbase.
Added in version 3.8.
- classmatplotlib.ticker.PercentFormatter(xmax=100,decimals=None,symbol='%',is_latex=False)[source]#
Bases:
Formatter
Format numbers as a percentage.
- Parameters:
- xmaxfloat
Determines how the number is converted into a percentage.xmax is the data value that corresponds to 100%.Percentages are computed as
x/xmax*100
. So if the data isalready scaled to be percentages,xmax will be 100. Another commonsituation is wherexmax is 1.0.- decimalsNone or int
The number of decimal places to place after the point.IfNone (the default), the number will be computed automatically.
- symbolstr or None
A string that will be appended to the label. It may beNone or empty to indicate that no symbol should be used. LaTeXspecial characters are escaped insymbol whenever latex mode isenabled, unlessis_latex isTrue.
- is_latexbool
IfFalse, reserved LaTeX characters insymbol will be escaped.
- format_pct(x,display_range)[source]#
Format the number as a percentage number with the correctnumber of decimals and adds the percent symbol, if any.
If
self.decimals
isNone
, the number of digits after thedecimal point is set based on thedisplay_range of the axisas follows:display_range
decimals
sample
>50
0
x=34.5
=> 35%>5
1
x=34.5
=> 34.5%>0.5
2
x=34.5
=> 34.50%...
...
...
This method will not be very good for tiny axis ranges orextremely large ones. It assumes that the values on the chartare percentages displayed on a reasonable scale.
- propertysymbol#
The configured percent symbol as a string.
If LaTeX is enabled via
rcParams["text.usetex"]
(default:False
), the special characters{'#','$','%','&','~','_','^','\','{','}'}
areautomatically escaped in the string.
- classmatplotlib.ticker.ScalarFormatter(useOffset=None,useMathText=None,useLocale=None,*,usetex=None)[source]#
Bases:
Formatter
Format tick values as a number.
- Parameters:
- useOffsetbool or float, default:
rcParams["axes.formatter.useoffset"]
(default:True
) Whether to use offset notation. See
set_useOffset
.- useMathTextbool, default:
rcParams["axes.formatter.use_mathtext"]
(default:False
) Whether to use fancy math formatting. See
set_useMathText
.- useLocalebool, default:
rcParams["axes.formatter.use_locale"]
(default:False
). Whether to use locale settings for decimal sign and positive sign.See
set_useLocale
.- usetexbool, default:
rcParams["text.usetex"]
(default:False
) To enable/disable the use of TeX's math mode for rendering thenumbers in the formatter.
Added in version 3.10.
- useOffsetbool or float, default:
Notes
In addition to the parameters above, the formatting of scientific vs.floating point representation can be configured via
set_scientific
andset_powerlimits
).Offset notation and scientific notation
Offset notation and scientific notation look quite similar at first sight.Both split some information from the formatted tick values and display itat the end of the axis.
The scientific notation splits up the order of magnitude, i.e. amultiplicative scaling factor, e.g.
1e6
.The offset notation separates an additive constant, e.g.
+1e6
. Theoffset notation label is always prefixed with a+
or-
signand is thus distinguishable from the order of magnitude label.
The following plot with x limits
1_000_000
to1_000_010
illustratesthe different formatting. Note the labels at the right edge of the x axis.- format_data(value)[source]#
Return the full string representation of the value with theposition unspecified.
- format_data_short(value)[source]#
Return a short string version of the tick value.
Defaults to the position-independent long value.
- get_useOffset()[source]#
Return whether automatic mode for offset notation is active.
This returns True if
set_useOffset(True)
; it returns False if anexplicit offset was set, e.g.set_useOffset(1000)
.See also
- set_locs(locs)[source]#
Set the locations of the ticks.
This method is called before computing the tick labels because someformatters need to know all tick locations to do so.
- set_powerlimits(lims)[source]#
Set size thresholds for scientific notation.
- Parameters:
- lims(int, int)
A tuple(min_exp, max_exp) containing the powers of 10 thatdetermine the switchover threshold. For a number representable as\(a \times 10^\mathrm{exp}\) with\(1 <= |a| < 10\),scientific notation will be used if
exp<=min_exp
orexp>=max_exp
.The default limits are controlled by
rcParams["axes.formatter.limits"]
(default:[-5,6]
).In particular numbers withexp equal to the thresholds arewritten in scientific notation.
Typically,min_exp will be negative andmax_exp will bepositive.
For example,
formatter.set_powerlimits((-3,4))
will providethe following formatting:\(1 \times 10^{-3}, 9.9 \times 10^{-3}, 0.01,\)\(9999, 1 \times 10^4\).
See also
- set_useLocale(val)[source]#
Set whether to use locale settings for decimal sign and positive sign.
- Parameters:
- valbool or None
None resets to
rcParams["axes.formatter.use_locale"]
(default:False
).
- set_useMathText(val)[source]#
Set whether to use fancy math formatting.
If active, scientific notation is formatted as\(1.2 \times 10^3\).
- Parameters:
- valbool or None
None resets to
rcParams["axes.formatter.use_mathtext"]
(default:False
).
- set_useOffset(val)[source]#
Set whether to use offset notation.
When formatting a set numbers whose value is large compared to theirrange, the formatter can separate an additive constant. This canshorten the formatted numbers so that they are less likely to overlapwhen drawn on an axis.
- Parameters:
- valbool or float
If False, do not use offset notation.
If True (=automatic mode), use offset notation if it can makethe residual numbers significantly shorter. The exact behavioris controlled by
rcParams["axes.formatter.offset_threshold"]
(default:4
).If a number, force an offset of the given value.
Examples
With active offset notation, the values
100_000,100_002,100_004,100_006,100_008
will be formatted as
0,2,4,6,8
plus an offset+1e5
, whichis written to the edge of the axis.
- propertyuseLocale#
Return whether locale settings are used for formatting.
See also
- propertyuseMathText#
Return whether to use fancy math formatting.
See also
- propertyuseOffset#
Return whether automatic mode for offset notation is active.
This returns True if
set_useOffset(True)
; it returns False if anexplicit offset was set, e.g.set_useOffset(1000)
.See also
- propertyusetex#
Return whether TeX's math mode is enabled for rendering.
- classmatplotlib.ticker.StrMethodFormatter(fmt)[source]#
Bases:
Formatter
Use a new-style format string (as used by
str.format
) to format the tick.The field used for the tick value must be labeledx and the field usedfor the tick position must be labeledpos.
The formatter will respect
rcParams["axes.unicode_minus"]
(default:True
) when formattingnegative numeric values.It is typically unnecessary to explicitly construct
StrMethodFormatter
objects, asset_major_formatter
directly accepts the format stringitself.
- classmatplotlib.ticker.SymmetricalLogLocator(transform=None,subs=None,linthresh=None,base=None)[source]#
Bases:
Locator
Place ticks spaced linearly near zero and spaced logarithmically beyond a threshold.
- Parameters:
- transform
SymmetricalLogTransform
, optional If set, defines thebase andlinthresh of the symlog transform.
- base, linthreshfloat, optional
Thebase andlinthresh of the symlog transform, as documentedfor
SymmetricalLogScale
. These parameters are only used iftransform is not set.- subssequence of float, default: [1]
The multiples of integer powers of the base where ticks are placed,i.e., ticks are placed at
[sub*base**iforiin...forsubinsubs]
.
- transform
Notes
Eithertransform, or bothbase andlinthresh, must be given.