Python | X-axis Scale Limit

Python | X-axis Scale Limit: In this article, we are going to learn about the X-axis Scale Limit and its Python implementation with example.
Submitted by Anuj Singh, on July 16, 2020

In some cases, we need to visualize our data within some defined range rather than the whole data. For this, we generally set the x-axis scale within a limit and this ultimately helps us to visualize better. Sometimes, it acts as zooming and a very helpful technique in data visualization. Therefore, Matplotlib has a defined function for this operation matplotlib.pyplot.xlim().

Following is an example showing a different X-axis Limit in plots using matplotlib.pyplot.

Syntax:

matplotlib.pyplot.xlim(left_limit, right_limit )
plt.show()
Python | X-axis Scale Limit (1)

Python | X-axis Scale Limit (2)

Python code for x-axis scale limit

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(500)
y1 = np.arange(500)
for i in range(500):
    y1[i] = 2*x[i] + np.random.randint(0,56)

plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line')
plt.ylabel('Function')
plt.title('Whole Data')

plt.figure()
plt.plot(x,y1)
plt.xlim(200,210)
plt.xlabel('Number Line')
plt.ylabel('Function')
plt.title('Limit for X axis is Set')

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.