Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack.
Matplotlib.axis.Axis.remove_overlapping_locs Function
The Axis.remove_overlapping_locs function in axis module of matplotlib library is used to trim the minor ticker locations that overlap with major ticker locations.
Syntax: Axis.remove_overlapping_locs
Parameters: This method accepts the following parameters.
- formatter: This parameter is the locator.
Return value: This method does not returns any value.
Below examples illustrate the matplotlib.axis.Axis.remove_overlapping_locs function in matplotlib.axis:
Example 1:
Python3
# Implementation of matplotlib function from matplotlib.axis import Axis import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator, ScalarFormatter fig, ax = plt.subplots() ax.plot([ 0 , 5 , 10 , 15 , 20 ], [ 3 , 2 , 1 , 2 , 4 ]) Axis.set_minor_locator(ax.xaxis, MultipleLocator( 1 )) Axis.set_minor_formatter(ax.xaxis, ScalarFormatter()) Axis.set_major_locator(ax.xaxis, MultipleLocator( 4 )) ax.tick_params(axis = 'both' , which = 'major' , labelsize = 14 , pad = 12 , colors = 'g' ) ax.tick_params(axis = 'both' , which = 'minor' , labelsize = 8 , colors = 'b' ) ax.xaxis.remove_overlapping_locs plt.title("Matplotlib.axis.Axis.remove_overlapping_locs \ Example", fontsize = 12 , fontweight = 'bold' ) plt.show() |
Output:
Example 2:
Python3
# Implementation of matplotlib function from matplotlib.axis import Axis import matplotlib.pyplot as plt import matplotlib.ticker as ticker from matplotlib.ticker import MultipleLocator, ScalarFormatter 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) Axis.set_major_locator(ax.xaxis, ticker.MultipleLocator( 3 )) Axis.set_minor_locator(ax.xaxis, ticker.MultipleLocator(tick_spacing)) Axis.set_minor_formatter(ax.xaxis, ScalarFormatter()) ax.xaxis.remove_overlapping_locs plt.title("Matplotlib.axis.Axis.remove_overlapping_locs \ Example", fontsize = 12 , fontweight = 'bold' ) plt.show() |
Output:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.