- 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 enforce axis range in Matplotlib?
To enforce axis range in matplotlib, we can take the following steps −
Set x and y limits using xlim and ylim methods, respectively.
Create x and y points for the curve using numpy.
Plot x and y using the plot() method.
To show the figure, use the show() method.
Example
import matplotlib.pyplot as plt import datetime import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([datetime.datetime(2021, 1, 1, i, 0) for i in range(24)]) y = np.random.randint(100, size=x.shape) plt.plot(x, y) plt.show()
Output
- Related Articles
- How to change the range of the X-axis and Y-axis in Matplotlib?
- How to annotate a range of the X-axis in Matplotlib?
- How to display Matplotlib Y-axis range using absolute values rather than offset values?
- How to set the range of Y-axis for a Seaborn boxplot using Matplotlib?
- How do I change the range of the X-axis with datetimes in Matplotlib?
- How to customize the X-axis in Matplotlib?
- How to customize X-axis ticks in Matplotlib?
- How to access axis label object in Matplotlib?
- How to remove relative shift in Matplotlib axis?
- How to set X-axis values in Matplotlib Python?
- How to add a second X-axis in Matplotlib?
- How to set the range of Y-axis in Python Plotly?
- How to share secondary Y-axis between subplots in Matplotlib?
- How to specify values on Y-axis in Python Matplotlib?
- How to draw axis lines inside a plot in Matplotlib?

Advertisements