How to change label font sizes in Seaborn

In Seaborn, we can adjust the font size of the labels in a plot with the help of the sns.set() function. However, the font_scale parameter of the sns.set() function scales the font size of all the elements in the plot, including tick labels, axes labels, titles, and legends, rather than selectively adjusting only the labels. To specifically modify the font size of the axes labels, i.e., x-axis and y-axis labels, we can utilize the functions from the matplotlib such as set_xlabel(), set_ylabel(), plt.xlabel(), and plt.ylabel() to set the font size of the labels.

Note: The fontsize parameter of set_xlabel() sets the label font size for selected plots in a figure, while in plt.xlabel(), it sets font size globally for the whole figure.

Syntax

We’ll use the following syntax to change the label font size:

# Using the font_scale parameter
sns.set(font_scale=1.0)
# Using Matplotlib to change specifically label font sizes using plt.xlabel()
plt.xlabel("sepal_length", fontsize=20)
plt.ylabel("petal_length", fontsize=20)
# Using Matplotlib to change specifically label font sizes using set_xlabel()
ax.set_xlabel("sepal_length", fontsize=20)
ax.set_ylabel("petal_length", fontsize=20)

The default value of font_scale is 1.01.0, which corresponds to the standard font size, but it can take any positive float value.

Note: The sns function is an alias of Seaborn.

Example

We'll plot scatterplot for a sample dataset provided by Seaborn and will analyze the working of font_scale parameter of sns.set() function. First, let's look at a plot without any font settings:

# Importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# Loading the iris dataset
iris_df = sns.load_dataset("iris")
# Setting the figure size but not the font size
sns.set(rc = {'figure.figsize':(20,8)})
# To Do
# Plotting the scatterplot
sns.scatterplot(x="sepal_length", y="petal_length", data=iris_df)
# show plot
plt.show()

As we can see, the labels are not legible because we have not yet set the font size. Once we use font_scale we will notice the clear difference in both plots:

# Importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# Loading the iris dataset
iris_df = sns.load_dataset("iris")
# Setting the figure size
sns.set(rc = {'figure.figsize':(20,10)})
# Setting the font size by 2.5
sns.set(font_scale=2.5)
# Plotting the scatterplot
sns.scatterplot(x="sepal_length", y="petal_length", data=iris_df)
# Showing plot
plt.show()

The text that was illegible because of the small font size has now become legible by using sns.set(font_scale=2.5). However, the text, in addition to the x-axis and y-axis label, has also increased in size. Let's see an example where we are using the set_xlabel() and set_ylabel(), and plt.xlabel() and plt.ylabel() to only increase the labels font sizes:

# Importing libraries
import seaborn as sns
import matplotlib.pyplot as plt
# Loading the iris dataset
iris_df = sns.load_dataset("iris")
# Setting the figure size
sns.set(rc = {'figure.figsize':(20,8)})
# Setting the font size by 2.5
# sns.set(font_scale=2.5)
# Plotting the scatterplot
ax = sns.scatterplot(x="sepal_length", y="petal_length", data=iris_df)
# Increasing the font size
# Uncommenting the following lines to see usage of plt.xlabel()
# plt.xlabel("sepal_length", fontsize=40)
# plt.ylabel("petal_length", fontsize=40)
# Increasing the font size using set_xlabel()
ax.set_xlabel("sepal_length", fontsize=40)
ax.set_ylabel("petal_length", fontsize=40)
# Showing the plot
plt.show()

Explanation

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

  • Lines 2–3: We import the seaborn and matplotlib libraries.

  • Line 12: We set the font size of the labels by giving a positive float value to the font_scale parameter.

  • Line 15: We draw the scatterplot of the iris dataset using the sns.scatterplot() function.

  • Lines 19–20: We can increase the font size using the plt.xlabel() and plt.ylabel() functions. Here, it is commented but we can uncomment it to check its utility.

  • Lines 23–24: We are using set_xlabel() and set_ylabel() to increase the font size to 4040.

  • Line 27: We display the plot using the plt.show() function.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved