A tick locator in Matplotlib decides where major and minor ticks fall on an axis. The default locator on linear axes is AutoLocator, a thin wrapper around MaxNLocator with sensible defaults, and it’s fine for most plots. When the defaults aren’t what we want, locators give explicit control.

The two locators that come up most often:

MaxNLocator(n) picks at most n ticks at nice values — multiples of 5, 10, 25, that sort of thing. Calling it without arguments lets it pick the count automatically. This is the locator to reach for when you want a clean default with a tick budget.

from matplotlib import ticker
ax.xaxis.set_major_locator(ticker.MaxNLocator(7))

MultipleLocator(d) places a tick at every multiple of d, regardless of the data range. MultipleLocator(5) puts ticks at 0, 5, 10, 15, 20, …. Use this when you want a specific, fixed spacing.

ax.xaxis.set_major_locator(ticker.MultipleLocator(5))

The difference: MaxNLocator adapts the spacing to the data range while staying within a tick count; MultipleLocator fixes the spacing and lets the count fall out wherever it lands.

There are parallel locators for minor ticks — the small ticks between the major ones — and corresponding set_minor_locator(...) methods. Minor ticks are useful when you want a fine-grained sense of position without the clutter of a label at every tick.

Beyond these two, Matplotlib has specialized locators for log scales (LogLocator), dates (DateLocator and friends in matplotlib.dates), and fixed positions (FixedLocator([...])). For most everyday plotting, MaxNLocator and MultipleLocator cover what’s needed.

Locators are paired with formatters, which decide what each tick says (the text label, as opposed to the position). ticker.FuncFormatter(...) lets you format tick labels arbitrarily — useful for adding units, switching to scientific notation, or transforming the displayed value.