How to Set the X and the Y Limit in Matplotlib with Python? Last Updated : 03 Oct, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will learn how to set the X limit and Y limit in Matplotlib with Python. Matplotlib is a visualization library supported by Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2002.xlim() is a function in the Pyplot module of the Matplotlib library which is used to get or set the x-limits of the current axes.ylim() is a function in the Pyplot module of the Matplotlib library which is used to get or set the y-limits of the current axes.Creating a Plot to Set the X and the Y Limit in Matplotlib Python3 # import packages import matplotlib.pyplot as plt import numpy as np # create data x = np.linspace(-10, 10, 1000) y = np.sin(x) # plot the graph plt.plot(x, y) Output: Simple PlotExample 1: Set X-Limit using xlim in Matplotlib Python3 # import packages import matplotlib.pyplot as plt import numpy as np # create data x = np.linspace(-10, 10, 1000) y = np.sin(x) # plot the graph plt.plot(x, y) # limit x by -5 to 5 plt.xlim(-5, 5) Output : X limited PlotExample 2: How to Set Y-Limit ylim in Matplotlib Python3 # import packages import matplotlib.pyplot as plt import numpy as np # create data x = np.linspace(-10, 10, 1000) y = np.cos(x) # plot the graph plt.plot(x, y) # limit y by 0 to 1 plt.ylim(0, 1) Output : Y Limited PlotExample 3: Set the X and the Y Limit in Matplotlib using xlim and ylim Python3 # import packages import matplotlib.pyplot as plt import numpy as np # create data x = np.linspace(-10, 10, 20) y = x # plot the graph plt.plot(x, y) # limited to show positive axes plt.xlim(0) plt.ylim(0) Output : X and Y Limited Plot RECOMMENDED ARTICLES - Formatting Axes in Python-Matplotlib Comment More infoAdvertise with us Next Article How to Set the X and the Y Limit in Matplotlib with Python? D deepanshu_rustagi Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads How to put the y-axis in logarithmic scale with Matplotlib ? In graphs, a logarithmic scale helps when numbers grow very fast, like 10, 100, 1000, and so on. Normally, in a graph, numbers increase by the same amount (like 1, 2, 3...), but in a logarithmic scale, they increase by multiplying (like 10, 100, 1000...). This makes it easier to see patterns in real 3 min read How to Set X-Axis Values in Matplotlib in Python? In this article, we will be looking at the approach to set x-axis values in matplotlib in a python programming language. The xticks() function in pyplot module of the Matplotlib library is used to set x-axis values. Syntax: matplotlib.pyplot.xticks(ticks=None, labels=None, **kwargs) xticks() functio 2 min read Python Plotly: How to set the range of the y axis? In this article, we will learn how to set the range of the y-axis of a graph using plotly in Python. To install this module type the below command in the terminal: pip install plotly Example 1: Using layout_yaxis_range as a parameter In this example, we have first import the required libraries i.e 3 min read How to Change the Line Width of a Graph Plot in Matplotlib with Python? Prerequisite : Matplotlib In this article we will learn how to Change the Line Width of a Graph Plot in Matplotlib with Python. For that one must be familiar with the given concepts: Matplotlib : Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a 2 min read How to Add Axes to a Figure in Matplotlib with Python? Matplotlib is a library in Python used to create figures and provide tools for customizing it. It allows plotting different types of data, geometrical figures. In this article, we will see how to add axes to a figure in matplotlib. We can add axes to a figure in matplotlib by passing a list argument 2 min read Like