matplotlib 3.5.1

BackRef

To remove in the future –– 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 specific custom ones.

Although the locators know nothing about major or minor ticks, they are used by 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 locators handle autoscaling of the view limits based on the data limits, and the choosing of tick locations. A useful semi-automatic tick locator is MultipleLocator . It is initialized with a base, e.g., 10, and it picks axis limits and ticks that are multiples of that base.

The Locator subclasses defined here are:

======================= ======================================================= AutoLocator MaxNLocator with simple defaults. This is the default tick locator for most plotting. MaxNLocator Finds up to a max number of intervals with ticks at nice locations. LinearLocator Space ticks evenly from min to max. LogLocator Space ticks logarithmically from min to max. MultipleLocator Ticks and range are a multiple of base; either integer or float. FixedLocator Tick locations are fixed. IndexLocator Locator for index plots (e.g., where x = range(len(y)) ). NullLocator No ticks. SymmetricalLogLocator Locator for use with with the symlog norm; works like LogLocator for the part outside of the threshold and adds 0 if inside the limits. LogitLocator Locator for logit scaling. AutoMinorLocator Locator for minor ticks when the axis is linear and the major ticks are uniformly spaced. Subdivides the major tick interval into a specified number of minor intervals, defaulting to 4 or 5 depending on the major interval. ======================= =======================================================

There are a number of locators specialized for date locations - see the .dates module.

You can define your own locator by deriving from Locator. You must override the __call__ method, which returns a sequence of locations, and you will probably want to override the autoscale method to set the view limits from the data limits.

If you want to override the default locator, use one of the above or a custom locator 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 is NullLocator , i.e., no minor ticks on by default.

note

:None:None:`Locator` instances should not be used with more than one :None:None:`~matplotlib.axis.Axis` or :None:None:`~matplotlib.axes.Axes`. 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 formatter operates on a single tick value and returns a string to the axis.

========================= ===================================================== NullFormatter No labels on the ticks. FixedFormatter Set the strings manually for the labels. FuncFormatter User defined function sets the labels. StrMethodFormatter Use string :None:None:`format` method. FormatStrFormatter Use an old-style sprintf format string. ScalarFormatter Default formatter for scalars: autopick the format string. LogFormatter Formatter for log axes. LogFormatterExponent Format values for log axis using exponent = log_base(value) . LogFormatterMathtext Format values for log axis using exponent = log_base(value) using Math text. LogFormatterSciNotation Format values for log axis using scientific notation. LogitFormatter Probability formatter. EngFormatter Format labels in engineering notation. PercentFormatter Format labels as a percentage. ========================= =====================================================

You can derive your own formatter from the Formatter base class by simply overriding the __call__ method. The formatter class has access to the axis view and data limits.

To control the major and minor tick label formats, use one of the following 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 a .Formatter instance, ~.Axis.set_major_formatter and ~.Axis.set_minor_formatter also accept a str or function. str input will be internally replaced with an autogenerated .StrMethodFormatter with the input str . For function input, a .FuncFormatter with the input function will be generated and used.

See /gallery/ticks/major_minor_demo for an example of setting major and minor ticks. See the matplotlib.dates module for more information and examples of using date locators and formatters.

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.signal._filter_design.iirdesign

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /matplotlib/ticker.py#0
type: <class 'module'>
Commit: