Categories
Python Answers

How to set y-axis limit in Python matplotlib?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *