Matplotlib.axis.Axis.set_ticklabels() Function
The Axis.set_ticklabels() function in axis module of matplotlib library is used to set the text values of the tick labels.
Syntax: Axis.set_ticklabels(self, ticklabels, \*args, minor=False, \*\*kwargs)
Parameters: This method accepts the following parameters.
- ticklabels : This parameter is the List of texts for tick labels.
- minor : This parameter contains the bool value.
Return value: This method returns the list of Texts.
Below examples illustrate the matplotlib.axis.Axis.set_ticklabels() function in matplotlib.axis:
Example 1:
Python3
# Implementation of matplotlib function from matplotlib.axis import Axis import matplotlib.pyplot as plt import numpy as np fig = plt.figure() x = np.linspace( 0 , 2 * np.pi, 100 ) y = 2 * np.sin(x) ax = fig.add_subplot() ax.plot(x,y) ax.yaxis.set_ticklabels([' ',' a ',' b ',' c ',' d', 'e' , 'f' , 'g' , 'h' , 'i' , '']) ax.xaxis.set_ticklabels([' ',' A ',' B ',' C ',' D', 'E' , 'F' , 'G' ,'']) ax.grid() fig.suptitle( """matplotlib.axis.Axis.set_ticklabels() function Example\n""" , fontweight = "bold") plt.show() |
Output:
Example 2:
Python3
# Implementation of matplotlib function from matplotlib.axis import Axis import matplotlib.pyplot as plt import numpy as np fig = plt.figure() x = np.linspace( - np.pi, np.pi, 100 ) y = 2 * np.sin(x) ax = fig.add_subplot() ax.set_title( 'centered spines' ) ax.plot(x, y) ax.spines[ 'left' ].set_position( 'center' ) ax.spines[ 'right' ].set_color( 'none' ) ax.spines[ 'bottom' ].set_position( 'center' ) ax.spines[ 'top' ].set_color( 'none' ) ax.xaxis.set_ticks_position( 'bottom' ) ax.yaxis.set_ticks_position( 'left' ) ax.xaxis.set_ticklabels([' ',' A ',' B ',' C ',' D', 'E' , 'F' , 'G' ,'']) ax.grid() fig.suptitle( """matplotlib.axis.Axis.set_ticklabels() function Example\n""" , fontweight = "bold") plt.show() |
Output:
Matplotlib.axis.Axis.set_ticklabels() function in Python
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.