Matplotlib.pyplot.locator_params() in Python Last Updated : 21 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Matplotlib is one of the most popular Python packages used for data visualization. It is a cross-platform library for making 2D plots from data in arrays.Pyplot is a collection of command style functions that make matplotlib work like MATLAB. Note: For more information, refer to Python Matplotlib – An Overview locator_params() is used for controlling the behaviors of tick locators. The attribute axis is for specifying on which axis is the function being applied. # for Y axis matplotlib.pyplot.locator_params(axis='y', nbins=3) # for X axis matplotlib.pyplot.locator_params(axis='x', nbins=3) # for both, x-axis and y-axis: Default matplotlib.pyplot.locator_params(nbins=3) Reducing the maximum number of ticks and use tight bounds: plt.locator_params(tight=True, nbins=4) Example 1: Python3 # importing libraries import matplotlib.pyplot as plt # Y-axis Values y =[-1, 4, 9, 16, 25] # X-axis Values x =[1, 2, 3, 4, 5] plt.locator_params(axis ='x', nbins = 5) # adding grid to the plot axes = plt.axes() axes.grid() # defining the plot plt.plot(x, y, 'mx', color ='green') # range of y-axis in the plot plt.ylim(ymin =-1.2, ymax = 30) # Set the margins plt.margins(0.2) # printing the plot plt.show() Output: Example 2: Python3 # importing libraries import matplotlib.pyplot as plt # defining the function def for_lines(xlab, ylab, plot_title, size_x, size_y, content =[]): width = len(content[0][1:]) s = [x for x in range(1, width + 1)] # specifying the size of figure plt.figure(figsize =(size_x, size_y)) for line in content: plt.plot(s, line[1:], 'ro--', color ='green', label = line[0]) # to add title to the plot plt.title(plot_title) # for adding labels to the plot plt.xlabel(xlab) plt.ylabel(ylab) t = len(s) plt.locator_params(nbins = t) for_lines("x-axis", "y-axis", "GeeksForGeeks", 7, 7, [[1, 2, 4, 3, 5]]) Output: Example 3: Python3 # importing libraries import matplotlib.pyplot as plt plt.locator_params(nbins = 10) # defining the plot plt.plot([1, 2, 3, 5, 7], [2, 3, 9, 15, 16], 'ro-', color ='red') # printing the plot plt.show() Output: Comment More infoAdvertise with us Next Article Matplotlib.pyplot.locator_params() in Python shardul_singh_tomar Follow Improve Article Tags : Python Write From Home Python-Library Python-matplotlib Practice Tags : python Similar Reads Matplotlib.pyplot.tick_params() in Python Matplotlib is a 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. matplotlib.pyplot.tick_params() matplotlib.pyplot.tick_params() is used to change the appearance 2 min read Matplotlib.axes.Axes.locator_params() in Python 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. 2 min read Matplotlib.pyplot.legend() in Python A legend is an area describing the elements of the graph. In the Matplotlib library, thereâs a function called legend() which is used to place a legend on the axes. In this article, we will learn about the Matplotlib Legends.Python Matplotlib.pyplot.legend() SyntaxSyntax: matplotlib.pyplot.legend([" 6 min read Matplotlib.pyplot.annotate() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.annotate() Function The annotate() function in pyplot module of matplotlib library is u 3 min read Matplotlib.pyplot.gca() in Python Matplotlib is a library in Python and it is a numerical - mathematical extension for the NumPy library. Pyplot is a state-based interface to a Matplotlib module that provides a MATLAB-like interface.  matplotlib.pyplot.gca() Function The gca() function in pyplot module of matplotlib library is used 2 min read Matplotlib.pyplot.ginput() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.sci() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.sca() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 1 min read Matplotlib.pyplot.gci() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.cla() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 1 min read Like