- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 force the Y axis to use only integers in Matplotlib?
Whenever Y value list will be made, then we will convert those datasets into a new list, with ceil and floor value of the given list accordingly. Then, we can plot the graph for the new list data.
Steps
Take an input list.
Find the minimum and maximum values in the input list (Step 1).
Create a range between min and max value (Step 2).
Get or set the current tick locations and labels of the Y-axis, with a new list.
Set the X-axis label using plt.xlabel() method.
Set the Y-axis label using plt.ylabel() method.
Set a title for the axes.
To show the figure we can use the plt.show() method.
Example
import math from matplotlib import pyplot as plt y = [0.17, 1.17, 2.98, 3.15, 4.11, 5.151] minimum_ele = min(y) maximum_ele = max(y) new_list = range(math.floor(min(y)), math.ceil(max(y))+1) plt.yticks(new_list) plt.xlabel("X-axis ") plt.ylabel("Y-axis ") plt.title("Only Integer on Y-axis ") plt.show()
Output
- Related Articles
- How to force Matplotlib to show the values on X-axis as integers?
- How to turn on minor ticks only on the y-axis Matplotlib?
- How to exponentially scale the Y axis with matplotlib?
- How to change the range of the X-axis and Y-axis in Matplotlib?
- How to specify values on Y-axis in Python Matplotlib?
- How to share secondary Y-axis between subplots in Matplotlib?
- How to print the Y-axis label horizontally in a Matplotlib/Pylab chart?
- How to repress scientific notation in factorplot Y-axis in Seaborn / Matplotlib?
- How to adjust 'tick frequency' in Matplotlib for string Y-axis?
- Setting Y-axis in Matplotlib using Pandas
- How to set the range of Y-axis for a Seaborn boxplot using Matplotlib?
- Show the origin axis (x,y) in Matplotlib plot
- How to customize the X-axis in Matplotlib?
- How to remove the first and last ticks label of each Y-axis subplot in Matplotlib?
- How to plot multiple Pandas columns on the Y-axis of a line graph (Matplotlib)?

Advertisements