Set axes limits
Functions for changing the limits:-
- matplotlib.axes.Axes.set_xlim() Function: axes module of matplotlib library is used to set the x-axis view limits.
- matplotlib.axes.Axes.set_ylim() Function: axes module of matplotlib library is used to set the y-axis view limits.
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: This parameter is the bottom xlim/ylim in data coordinates
- top: This parameter is the top xlim/ylim in data coordinates
- emit: This parameter is used to notify observers of limit change.
- auto: This parameter is used to turn on autoscaling of the x-axis/y-axis.
- xmin, xmax, ymin, ymax: These parameters are equivalent to bottom and top and it is an error to pass both xmin/ymin and bottom or xmax/ymax and top.
Returns: bottom, top: This returns the new x-axis/y-axis limits in data coordinates.
Example:
Python3
# import packages import matplotlib.pyplot as plt import seaborn as sns # create data data = [ 3 , 7 , 9 , 11 , 12 , 14 , 15 , 16 , 18 , 19 , 20 , 23 , 25 , 28 ] # plot distplot fig, ax = plt.subplots() sns.distplot(data, ax = ax) # change the limits of X-axis ax.set_xlim( 1 , 70 ) plt.show() |
Output:
How to set axes labels & limits in a Seaborn plot?
In this article, we will learn How to set axes labels & limits in a Seaborn plot. Let’s discuss some concepts first.
- Axis is the region in the plot that contains the data space. The Axes contain two or three-axis(in case of 3D) objects which take care of the data limits.
- Axes Labels are the labels that describe the axes’ values in terms of meaning, units, and direction.
- Axes Limits are the limits to the axes’ values, which are used to filter for a required value on axes.
Here, In this article, the content goes from setting the axes labels, axes limits, and both at a time. In the end, you will be able to learn how to set axes labels & limits in a Seaborn plot.