- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set X-axis values in Matplotlib Python?
To set X-axis values in matplotlib in Python, we can take the following steps −
Create two lists for x and y data points.
Get the xticks range value.
Plot a line using plot() method with xtick range value and y data points.
Replace xticks with X-axis value using xticks() method.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [45, 1, 34, 78, 100] y = [8, 10, 23, 78, 2] default_x_ticks = range(len(x)) plt.plot(default_x_ticks, y) plt.xticks(default_x_ticks, x) plt.show()
Output
- Related Articles
- How to set "step" on axis X in my figure in Matplotlib Python 2.6.6?
- How to specify values on Y-axis in Python Matplotlib?
- How to set axis ticks in multiples of pi in Python Matplotlib?
- How to set my xlabel at the end of X-axis in Matplotlib?
- Updating the X-axis values using Matplotlib animation
- How to force Matplotlib to show the values on X-axis as integers?
- Aligning table to X-axis using matplotlib Python
- How to place X-axis grid over a spectrogram in Python Matplotlib?
- How to customize the X-axis in Matplotlib?
- How to customize X-axis ticks in Matplotlib?
- How to add a second X-axis in Matplotlib?
- How to show all the X-axis tick values in Python Plotly?
- How to set Dataframe Column value as X-axis labels in Python Pandas?
- How to set the unit length of an axis in Matplotlib?
- How to set the value of the axis multiplier in matplotlib?

Advertisements