setting y-axis limit in matplotlib setting y-axis limit in matplotlib python python

setting y-axis limit in matplotlib


Try this . Works for subplots too .

axes = plt.gca()axes.set_xlim([xmin,xmax])axes.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 pltplt.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)


matomo