Skip to content

Improve documentation for ticker #24243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,10 +1707,10 @@ def tick_values(self, vmin, vmax):

class FixedLocator(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
Tick locations are fixed at *locs*. If *nbins* is not None,
the *locs* array of possible positions will be subsampled to
keep the number of ticks <= *nbins* +1.
The subsampling will be done 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.
Expand Down Expand Up @@ -1774,14 +1774,21 @@ class LinearLocator(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 to make a nice tick partitioning. Thereafter, the
number of ticks will be fixed so that interactive navigation will
be nice

"""
def __init__(self, numticks=None, presets=None):
"""
Use presets to set locs based on lom. A dict mapping vmin, vmax->locs
Parameters
----------
numticks : int or None, default None
Number of ticks. If None, *numticks* = 11.
presets : dict or None, default: None
Dictionary mapping ``(vmin, vmax)`` to an array of locations.
Overrides *numticks* if there is an entry for the current
``(vmin, vmax)``.
"""
self.numticks = numticks
if presets is None:
Expand Down Expand Up @@ -1847,7 +1854,8 @@ def view_limits(self, vmin, vmax):

class MultipleLocator(Locator):
"""
Set a tick on each integer multiple of a base within the view interval.
Set a tick on each integer multiple of the *base* within the view
interval.
"""

def __init__(self, base=1.0):
Expand All @@ -1874,7 +1882,7 @@ def tick_values(self, vmin, vmax):

def view_limits(self, dmin, dmax):
"""
Set the view limits to the nearest multiples of base that
Set the view limits to the nearest multiples of *base* that
contain the data.
"""
if mpl.rcParams['axes.autolimit_mode'] == 'round_numbers':
Expand Down Expand Up @@ -1903,16 +1911,20 @@ def scale_range(vmin, vmax, n=1, threshold=100):

class _Edge_integer:
"""
Helper for MaxNLocator, MultipleLocator, etc.
Helper for `.MaxNLocator`, `.MultipleLocator`, etc.

Take floating point precision limitations into account when calculating
Take floating-point precision limitations into account when calculating
tick locations as integer multiples of a step.
"""
def __init__(self, step, offset):
"""
*step* is a positive floating-point interval between ticks.
*offset* is the offset subtracted from the data limits
prior to calculating tick locations.
Parameters
----------
step : float > 0
Interval between ticks.
offset : float
Offset subtracted from the data limits prior to calculating tick
locations.
"""
if step <= 0:
raise ValueError("'step' must be positive")
Expand Down Expand Up @@ -1946,8 +1958,8 @@ def ge(self, x):

class MaxNLocator(Locator):
"""
Find nice tick locations with no more than N being within the view limits.
Locations beyond the limits are added to support autoscaling.
Find nice tick locations with no more than *nbins* + 1 being within the
view limits. Locations beyond the limits are added to support autoscaling.
"""
default_params = dict(nbins=10,
steps=None,
Expand Down