Sometimes, we want to set y-axis limit in Python matplotlib.
In this article, we’ll look at how to set y-axis limit in Python matplotlib.
How to set y-axis limit in Python matplotlib?
To set y-axis limit in Python matplotlib, we can use the set_xlim
and set_ylim
methods.
For instance, we write
ax = plt.gca()
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
to get the axes of the plot with
ax = plt.gca()
Then we write
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
to set the limits of the x and y axes respectively with the set_xlim
and set_ylim
methods.
Conclusion
To set y-axis limit in Python matplotlib, we can use the set_xlim
and set_ylim
methods.