# How to Set X-Axis Values in Matplotlib in Python?

• Last Updated : 13 Sep, 2022

In this article, we will be looking at the approach to set x-axis values in matplotlib in a python programming language.

The xticks() function in pyplot module of the Matplotlib library is used to set x-axis values.

Syntax:

matplotlib.pyplot.xticks(ticks=None, labels=None, **kwargs)

xticks() function accepts the following parameters:

Returns: xticks() function returns following values:

• locs: List of xticks location.
• labels: List of xlabel text location.

Example #1 :

In this example, we will be setting up the X-Axis Values in Matplotlib using the xtick() function in the python programming language.

## Python3

 # Python program to set x-axis values in matplotlib import matplotlib.pyplot as plt # x-axis and y-axis values for plottingx = [1, 2, 3, 4, 5, 6]y = [3, 1, 4, 5, 3, 6] # labels for x-asixlabels = ['A', 'B', 'C', 'D', 'E', 'F'] # Plotting x-axis and y-axisplt.plot(x, y) # naming of x-axis and y-axisplt.xlabel("X-Axis")plt.ylabel("Y-Axis") # naming the title of the plotplt.title("Set X-Axis Values in Matplotlib") # setting x-axis valuesplt.xticks(x, labels) plt.show()

Output:

Example #2:

In this example, we will use the rotation argument to accept rotation value in degree and it will rotate labels in the clockwise direction by specified degree.

## Python3

 # Python program to set x-axis values in matplotlib import matplotlib.pyplot as plt # x-axis and y-axis values for plottingx = [1, 2, 3, 4, 5, 6]y = [3, 1, 4, 5, 3, 6] # labels for x-asixlabels = ['Label1', 'Label2', 'Label3', 'Label4', 'Label5', 'Label6'] # Plotting x-axis and y-axisplt.plot(x, y) # naming of x-axis and y-axisplt.xlabel("X-Axis")plt.ylabel("Y-Axis") # naming the title of the plotplt.title("Set X-Axis Values in Matplotlib") # setting x-axis values and specifying rotation# for the labels in degreesplt.xticks(x, labels, rotation=45) plt.show()

Output:

My Personal Notes arrow_drop_up