Open In App

Matplotlib.axes.Axes.locator_params() in Python

Last Updated : 21 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

matplotlib.axes.Axes.locator_params() Function

The Axes.locator_params() function in axes module of matplotlib library is used to control behavior of major tick locators.
Syntax: Axes.locator_params(self, axis='both', tight=None, **kwargs) Parameters: This method accepts the following parameters.
  • axis : This parameter is the axis on which to operate
  • .
  • tight : This parameter is passed to autoscale_view. Default is None, for no change.
Return value: This method does not returns any value.
Below examples illustrate the matplotlib.axes.Axes.locator_params() function in matplotlib.axes: Example 1: Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.gridspec as gridspec
import numpy as np
 
 
plt.rcParams['savefig.facecolor'] = "0.8"
plt.rcParams['figure.figsize'] = 6, 5
 
fig, ax = plt.subplots()
 
ax.plot([1, 2])
 
ax.locator_params("x", nbins = 3)
ax.locator_params("y", nbins = 5)
 
ax.set_xlabel('x-label')
ax.set_ylabel('y-label')
 
fig.suptitle('matplotlib.axes.Axes.locator_params() \
function Example\n\n', fontweight ="bold")
plt.show()
Output: Example 2: Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.gridspec as gridspec
import numpy as np


arr = np.arange(100).reshape((10, 10))
norm = mcolors.Normalize(vmin = 0., vmax = 100.)

pc_kwargs = {'rasterized': True, 'cmap': 'viridis',
             'norm': norm}

fig, (ax, ax1) = plt.subplots(1, 2)

im = ax.pcolormesh(arr, **pc_kwargs)
fig.colorbar(im, ax = ax, shrink = 0.6)

im1 = ax1.pcolormesh(arr, **pc_kwargs)
ax1.locator_params(nbins = 3)
fig.colorbar(im1, ax = ax1, shrink = 0.6)

ax.set_title("Without locator_params()")
ax1.set_title("With locator_params()")

fig.suptitle('matplotlib.axes.Axes.locator_params() \
function Example\n\n', fontweight ="bold")
plt.show()
Output:

Next Article
Article Tags :
Practice Tags :

Similar Reads