Articles → Matplotlib → Set_Xlim And Set_Ylim Function In Matplotlib

Set_Xlim And Set_Ylim Function In Matplotlib






Purpose


  1. Set_xlim function specifies minimum and maximum limit of x-axis.
  2. Set_ylim function specifies minimum and maximum limit of y-axis.

Example


import matplotlib.pyplot as plt
import array 

arr1 = array.array('i', [1, 2, 3])
arr2 = array.array('i', [4, 5, 6])

# Create a figure object
fig = plt.figure()
# add axis
axes = fig.add_axes([.1,.1,.8,.8])
# Plot graph
axes.plot(arr1,arr2, marker='o')
plt.xlim([0.5, 3])
plt.ylim([0.5, 6])
# Show graph
plt.show()




  1. Minimum limit of x-axis is .5 and maximum is 3.
  2. Minimum limit of y-axis is .5 and maximum is 6.

Output


Picture showing the output of set_xlim and set_ylim function in matplotlib



Posted By  -  Karan Gupta
 
Posted On  -  Thursday, June 20, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250