- 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 remove the digits after the decimal point in axis ticks in Matplotlib?
To remove the digits after the decimal point in axis ticks in Matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create x and y data points using numpy.
Create a figure and a set of subplots.
To set the xtick labels only in digits, we can use x.astype(int) method.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([1.110, 2.110, 4.110, 5.901, 6.00, 7.90, 8.90]) y = np.array([2.110, 1.110, 3.110, 9.00, 4.001, 2.095, 5.890]) fig, ax = plt.subplots() ax.plot(x, y) ax.set_xticklabels(x.astype(int)) plt.show()
Output
- Related Articles
- Remove the X-axis ticks while keeping the grids (Matplotlib)
- How to remove the first and last ticks label of each Y-axis subplot in Matplotlib?
- How to customize X-axis ticks in Matplotlib?
- How do you draw R-style axis ticks that point outward from the axes in Matplotlib?
- How to remove decimal point?
- How to set axis ticks in multiples of pi in Python Matplotlib?
- How to turn on minor ticks only on the y-axis Matplotlib?
- Adding extra axis ticks using Matplotlib
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- How to remove relative shift in Matplotlib axis?
- How to move the Y-axis ticks from the left side of the plot to the right side in matplotlib?
- How to change the spacing between ticks in Matplotlib?
- How to change the axis ticks color in base R plot?
- How to set the number of ticks in plt.colorbar in Matplotlib?
- Counting numbers after decimal point in JavaScript

Advertisements