Matplotlib - X-axis Label
Matplotlib - X-axis label
In Matplotlib, you can add a label to the X-axis to provide context and information about the data being visualized along the horizontal axis.
The X-axis label can be specified using xlabel()
function of matplotlib.pyplot
. Pass the label value as argument to the xlabel() function, and the given value shall be displayed as label along the X-axis of the plot.
For example, in the following program, we shall plot a line graph, and then specify X-axis label as 'X-axis Sample Label'
. You may change the value for label as per your requirement.
Python Program
import matplotlib.pyplot as plt
# Example data
x = [1, 2, 3, 4, 5]
y = [10, 20, 35, 45, 30]
# Plot the data
plt.plot(x, y, marker='o')
# Add a label to the X-axis
plt.xlabel('X-axis Sample Label')
# Show the plot
plt.show()
Output