setting y-axis limit in matplotlib

Get current axis via plt.gca(), and then set its limits:

ax = plt.gca()
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])

Another workaround is to get the plot's axes and reassign changing only the y-values:

x1,x2,y1,y2 = plt.axis()  
plt.axis((x1,x2,25,250))

One thing you can do is to set your axis range by yourself by using matplotlib.pyplot.axis.

matplotlib.pyplot.axis

from matplotlib import pyplot as plt
plt.axis([0, 10, 0, 20])

0,10 is for x axis range. 0,20 is for y axis range.

or you can also use matplotlib.pyplot.xlim or matplotlib.pyplot.ylim

matplotlib.pyplot.ylim

plt.ylim(-2, 2)
plt.xlim(0,10)