How to change the range of the x-axis and y-axis in matlibplot?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to change the range of the x-axis and y-axis in matlibplot in Python. So Here I am Explain to you all the possible Methods here.

How to change the range of the x-axis and y-axis in matlibplot?

1. How to change the range of the x-axis and y-axis in matlibplot?

Use first xticks and yticks before xlim and ylim. This will create an array before it sets the limit

2. change the range of the x-axis and y-axis in matlibplot

Use first xticks and yticks before xlim and ylim. This will create an array before it sets the limit

Method 1

To change the axes range, you can use

plt.xlim([-3, 3])
plt.ylim([-3, 3])

You will then have to remove the line plt.axis('scaled') for this to work.

import numpy as np
import matplotlib.pyplot as plt
import scipy, pylab

plt.axes()
plt.xlim([-3, 3])
plt.ylim([-3, 3])
plt.yticks(np.arange(-3, 3, 0.25))
plt.xticks(np.arange(-3, 3, 0.25))
plt.show()

Method 2

Use first xticks and yticks before xlim and ylim. This will create an array before it sets the limit

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.