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

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

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