How to change the figure size in seaborn

Seaborn is a Python visualization library built on top of matplotlib that offers a high-level interface for creating visually appealing and statistical visuals. We will use seaborn to change the figure size of a plot.

Syntax

To change the figure size in seaborn, the following syntax is used:

width = 20
height = 8
sns.set(rc = {'figure.figsize':(width, height)})

Here, sns.set() is being used to set the figure size of the plot. Although it can also be used to set the other properties of the plot.

Note: sns is an alias of seaborn

Code example

Let’s create a scatter plot of tips dataset by loading it from seaborn. The width and height are currently set as 2020 and 88, respectively. But these values can be changed according to the required size of the figure. Try different sizes of the figure by changing the width and height in the following code:

# importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# Load tips dataset
tips = sns.load_dataset("tips")
# setting the figure size
width = 20
height = 8
sns.set(rc = {'figure.figsize':(width,height)})
# setting the font of plot
sns.set(font_scale=1.5)
# plotting the scatterplot
sns.scatterplot(x="total_bill", y="tip", data=tips)
# show plot
plt.show()

Code explanation

Here is a line-by-line explanation of the code above:

  • Lines 9–11: We set the size of the figure by using sns.set(). Here, width and height is set as 2020 and 88, respectively.

  • Line 14: We draw the scatter plot of the tips dataset using the sns.scatterplot() function.

  • Line 17: The plt.show() function is used to display the plot.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved