Skip to content
Related Articles
Open in App
Not now

Related Articles

Matplotlib.ticker.MultipleLocator Class in Python

Improve Article
Save Article
  • Last Updated : 21 Apr, 2020
Improve Article
Save Article

Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.


The matplotlib.ticker.MultipleLocator class is used for setting a tick for every integer multiple of a base within the view interval.

Syntax: class matplotlib.ticker.MultipleLocator(base=1.0)

Methods of the class:

  • set_params(self, base): It is used for setting the parameters within the locator.
  • tick_values(self, vmin, vmax): For a given vmin and vmax it returns the values of the located ticks.
  • view_limits(self, dmin, dmax): It is used for setting the view limits to the nearest multiples of base that contain the data.

Example 1:

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
x = [0, 5, 9, 10, 15]
y = [0, 1, 2, 3, 4]
tick_spacing = 1
fig, ax = plt.subplots(1, 1)
ax.plot(x, y)


Example 2:

import matplotlib.pyplot as plt
import matplotlib.ticker
plt.plot([-1.5, 0, 1.5], [1, 3, 2])
ax = plt.gca()
func = lambda x, pos: str(x).rstrip('0').rstrip('.')


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!