chevron_left
Axes Cookbook
0
0
0
new
Setting x-axis limit in Matplotlib
Programming
chevron_rightPython
chevron_rightMatplotlib
chevron_rightCookbooks
chevron_rightAxes Cookbook
schedule Mar 10, 2022
Last updated Python●Matplotlib
Tags tocTable of Contents
expand_more To set a limit on the x-axis (i.e. the domain), use the xlim(~)
method:
import matplotlib.pyplot as plt
plt.plot([1,2,3])plt.xlim(0,4)plt.show()
The result is as follows:

Notice how the x-axis goes from 0 to 4, as specified.
Alternatively you can use the set_xlim(~)
method:
fig, ax = plt.subplots()ax.set_xlim(0,4)
This produces the following output:

Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...