How to change axes limits in matplotlib? Last Updated : 16 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Sometimes, when you create a plot default axes X and Y may not show the full picture you want. Changing the axes limits helps you focus on specific data ranges or improve how your plot looks. There are two methods available in Axes module tochange the limits:matplotlib.axes.Axes.set_xlim(): It is used to set the x-axis view limits. We can specify the lower and upper bounds for the x-axis. This helps zoom in or zoom out graph along the x-axis to highlight specific portions of data.matplotlib.axes.Axes.set_ylim(): It is used to set the y-axis view limits. We can define the range for the y-axis to control which portion of the data is visible along y-axis.Syntax:Axes.set_xlim(self, left=None, right=None, emit=True, auto=False, *, xmin=None, xmax=None)Axes.set_ylim(self, bottom=None, top=None, emit=True, auto=False, *, ymin=None, ymax=None)Parameters:bottom/top: Defines the lower/upper limit of the x or y axis in data coordinates.emit: Notifies observers when the limit changes.auto: Enables auto scaling for the axis.xmin/xmax/ymin/ymax: Alternate methods for bottom and top. It will generate error if wepass both xmin/ymin and bottom or xmax/ymax and top.Example 1: Here ax.set_xlim(1, 70): This sets the limits for the x-axis(1- lower bound and 70 -upper bound ) Python import seaborn as sns data = [3, 7, 9, 11, 12, 14, 15, 16, 18, 19, 20, 23, 25, 28] fig, ax = plt.subplots() sns.distplot(data, ax=ax) ax.set_xlim(1, 70) plt.show() Output: Example 2:Now lets see the implementation for matplotlib.axes.Axes.set_ylim().Here we will load the "tips" dataset which is a built-in dataset in Seaborn. It contains information about restaurant bills and tips. Here gfg.set_ylim(0, 80) sets the y-axis limits and will range from 0 to 80 regardless of the data's actual range. Python import seaborn as sns import matplotlib.pyplot as plt sns.set_style("whitegrid") tips = sns.load_dataset("tips") day_colors = { "Thur": "blue", "Fri": "orange", "Sat": "green", "Sun": "red" } gfg = sns.boxplot(x="day", y="total_bill", data=tips, palette=day_colors) gfg.set_ylim(0, 80) plt.show() Output: Changing axes limits in Seaborn is a simple yet essential technique for customizing your visualizations. By adjusting the X and Y axis ranges, you can focus on specific areas of interest in your data, highlight important trends and improve overall clarity of your plots.You can also read realted articles:matplotlib.axes.Axes.set_xlim()matplotlib.axes.Axes.set_ylim() Comment More infoAdvertise with us Next Article How to Reverse Axes in Matplotlib G geetansh044 Follow Improve Article Tags : Python Python-Seaborn Practice Tags : python Similar Reads How to change the size of axis labels in Matplotlib? Matplotlib is a Python library that helps in visualizing and customizing various plots. One of the customization you can do is to change the size of the axis labels to make reading easier. In this guide, weâll look how to adjust font size of axis labels using Matplotlib.Letâs start with a basic plot 2 min read Matplotlib.axes.Axes.margins() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.axes.Axes.inset_axes() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read How to Reverse Axes in Matplotlib Matplotlib allows you to reverse X-axis, Y-axis or both using multiple approaches. This is useful when we want to visualize data from a different view like reversing the order of time in a time-series or switching the direction of the axes according to our needs.Method 1: Using invert_xaxis() and in 3 min read Matplotlib.axes.Axes.axis() in Python The Axes.axis() function in Matplotlib is used to get or set the properties of the x-axis and y-axis limits on a given Axes object. It provides an easy way to control the view limits, aspect ratio, and visibility of the axes in a plot. It's key feature include:Get the current axis limits as [xmin, x 2 min read matplotlib.axes.Axes.axhspan() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Like