This module contains classes to support completely configurable tick locating and formatting. 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. Generic tick locators and formatters are provided, as well as domain specific custom ones..
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. You initialize this with a base, eg 10, and it picks axis limits and ticks that are multiples of your base.
The Locator subclasses defined here are
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( xmajorLocator )
ax.xaxis.set_minor_locator( xminorLocator )
ax.yaxis.set_major_locator( ymajorLocator )
ax.yaxis.set_minor_locator( yminorLocator )
The default minor locator is the NullLocator, eg no minor ticks on by default.
Tick formatting is controlled by classes derived from Formatter. The formatter operates on a single tick value and returns a string to the axis.
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( xmajorFormatter )
ax.xaxis.set_minor_formatter( xminorFormatter )
ax.yaxis.set_major_formatter( ymajorFormatter )
ax.yaxis.set_minor_formatter( yminorFormatter )
See pylab_examples example code: major_minor_demo1.py for an example of setting major an minor ticks. See the matplotlib.dates module for more information and examples of using date locators and formatters.
Bases: matplotlib.ticker.TickHelper
Convert the tick location to a string
some classes may want to replace a hyphen for minus with the proper unicode symbol as described here. The default is to do nothing
Note, if you use this method, eg in :meth`format_data` or call, you probably don’t want to use it for format_data_short() since the toolbar uses this for interative coord reporting and I doubt we can expect GUIs across platforms will handle the unicode correctly. So for now the classes that override fix_minus() should have an explicit format_data_short() method
Bases: matplotlib.ticker.Formatter
Return fixed strings for tick labels
seq is a sequence of strings. For positions i < len(seq) return seq[i] regardless of x. Otherwise return ‘’
Bases: matplotlib.ticker.Formatter
Always return the empty string
Bases: matplotlib.ticker.Formatter
User defined function for formatting
Bases: matplotlib.ticker.Formatter
Use a format string to format the tick
Bases: matplotlib.ticker.Formatter
Tick location is a plain old number. If useOffset==True and the data range is much smaller than the data average, then an offset will be determined such that the tick labels are meaningful. Scientific notation is used for data < 1e-3 or data >= 1e4.
Sets size thresholds for scientific notation.
e.g. formatter.set_powerlimits((-3, 4)) sets the pre-2007 default in which scientific notation is used for numbers less than 1e-3 or greater than 1e4. See also set_scientific().
Bases: matplotlib.ticker.Formatter
Format values for log axis;
if attribute decadeOnly is True, only the decades will be labelled.
base is used to locate the decade tick, which will be the only one to be labeled if labelOnlyBase is False
Bases: matplotlib.ticker.LogFormatter
Format values for log axis; using exponent = log_base(value)
base is used to locate the decade tick, which will be the only one to be labeled if labelOnlyBase is False
Bases: matplotlib.ticker.LogFormatter
Format values for log axis; using exponent = log_base(value)
base is used to locate the decade tick, which will be the only one to be labeled if labelOnlyBase is False
Bases: matplotlib.ticker.TickHelper
Determine the tick locations;
Note, you should not use the same locator between different Axis because the locator stores references to the Axis data and view limits
select a scale for the range from vmin to vmax
Normally This will be overridden.
Bases: matplotlib.ticker.Locator
Place a tick on every multiple of some base number of points plotted, eg on every 5th point. It is assumed that you are doing index plotting; ie the axis is 0, len(data). This is mainly useful for x ticks.
place ticks on the i-th data points where (i-offset)%base==0
Bases: matplotlib.ticker.Locator
Tick locations are fixed. If nbins is not None, the array of possible positions will be subsampled to keep the number of ticks <= nbins +1. The subsampling will be done so as to include the smallest absolute value; for example, if zero is included in the array of possibilities, then it is guaranteed to be one of the chosen ticks.
Bases: matplotlib.ticker.Locator
No ticks
Bases: matplotlib.ticker.Locator
Determine the tick locations
The first time this function is called it will try to set the number of ticks to make a nice tick partitioning. Thereafter the number of ticks will be fixed so that interactive navigation will be nice
Use presets to set locs based on lom. A dict mapping vmin, vmax->locs
Bases: matplotlib.ticker.Locator
Determine the tick locations for log axes
place ticks on the location= base**i*subs[j]
Bases: matplotlib.ticker.Locator
Set a tick on every integer that is multiple of base in the view interval
Bases: matplotlib.ticker.Locator
Select no more than N intervals at nice locations.
Keyword args: prune
Remove edge ticks – useful for stacked or ganged plots where the upper tick of one axes overlaps with the lower tick of the axes above it. One of ‘lower’ | ‘upper’ | ‘both’ | None. If prune==’lower’, the smallest tick will be removed. If prune==’upper’, the largest tick will be removed. If prune==’both’, the largest and smallest ticks will be removed. If prune==None, no ticks will be removed.