Skip to content
Related Articles

Related Articles

How to change axes limits in Seaborn?
  • Last Updated : 17 Feb, 2021
GeeksforGeeks - Summer Carnival Banner

Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. There are two methods available in the Axes module to change the limits:

  1. matplotlib.axes.Axes.set_xlim(): Axes module of matplotlib library is used to set the x-axis view limits.
  2. matplotlib.axes.Axes.set_ylim(): Axes module of matplotlib library is used to set the y-axis view limits.


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)


  • 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 parametersthe are equivalent to bottom and top and it is an error to pass both xmin/ymin and bottom or xmax/ymax and top.


   bottom, top: This returns the new x-axis/y-axis limits in data coordinates.

Example 1:


# Import module
import matplotlib.pyplot as plt
import seaborn as sns
# assing data
data = [3, 7, 9, 11, 12, 14
        15, 16, 18, 19, 20
        23, 25, 28]
# depict visualization
fig, ax = plt.subplots()
sns.distplot(data, ax=ax)
ax.set_xlim(1, 70)


Example 2:


# import module
import seaborn as sns
# assign dataset
tips = sns.load_dataset("tips")
# depict visualization
gfg = sns.boxplot(x="day", y="total_bill"
gfg.set_ylim(0, 80)


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :