- 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
Change x axes scale in matplotlib
Using plt.xticks, we can change the X-axis scale.
Steps
Using plt.plot() method, we can create a line with two lists that are passed in its argument.
Add text to the axes. Add the text *s* to the axes at location *x*, *y* in data coordinates, using plt.text() method, where the font size can be customized by changing the font-size value.
Using xticks method, get or set the current tick locations and labels of the X-axis.
To show the figure, use plt.show() method.
Example
import matplotlib.pyplot as plt plt.plot([1, 2, 4], [1, 2, 4]) plt.text(2, 3, "y=x", color='red', fontsize=20) plt.xticks([1, 2, 3, 4, 5]) # changing x scale by own plt.show()
Output
- Related Articles
- How to label and change the scale of a Seaborn kdeplot's axes? (Matplotlib)
- How to change axes background color in Matplotlib?
- How to scale axes in Mplot3d?
- How to change the scale of an existing table in Matplotlib?
- How do I plot multiple X or Y axes in Matplotlib?
- How can I change the font size of ticks of axes object in Matplotlib?
- How do I change the font size of the scale in Matplotlib plots?
- How to change the scale of imshow in matplotlib without stretching the image?
- How to switch axes in Matplotlib?
- Multiple axes in Matplotlib with different scales
- Plot 3D bars without axes in Matplotlib
- Rotating axes label text in 3D Matplotlib
- How to make axes transparent in Matplotlib?
- How to share x axes of two subplots after they have been created in Matplotlib?
- Setting active subplot using axes object in Matplotlib

Advertisements