You are reading an old version of the documentation (v2.2.3). For the latest version see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xlim.html
Version 2.2.3
matplotlib
Fork me on GitHub

Table Of Contents

matplotlib.pyplot.xlim

matplotlib.pyplot.xlim(*args, **kwargs)[source]

Get or set the x limits of the current axes.

Call signatures:

xmin, xmax = xlim()  # return the current xlim
xlim((xmin, xmax))   # set the xlim to xmin, xmax
xlim(xmin, xmax)     # set the xlim to xmin, xmax

If you do not specify args, you can pass xmin or xmax as kwargs, i.e.:

xlim(xmax=3)  # adjust the max leaving min unchanged
xlim(xmin=1)  # adjust the min leaving max unchanged

Setting limits turns autoscaling off for the x-axis.

Returns:
xmin, xmax

A tuple of the new x-axis limits.

Notes

Calling this function with no arguments (e.g. xlim()) is the pyplot equivalent of calling get_xlim on the current axes. Calling this function with arguments is the pyplot equivalent of calling set_xlim on the current axes. All arguments are passed though.