Table of Contents
Changing the font size in Seaborn plots can be achieved by utilizing the “font_scale” parameter in the “set” function. This parameter allows for easy adjustment of the font size in all the elements of a plot, including the title, axes labels, and tick labels. By specifying a larger or smaller font scale, the overall font size in the plot can be modified, providing more flexibility in customizing the visual appearance of the plot. This simple method can greatly enhance the readability and aesthetic appeal of Seaborn plots.
Change Font Size in Seaborn Plots (With Examples)
You can use the following basic syntax to change the font size in Seaborn plots:
import seaborn as sns sns.set(font_scale=2)
Note that the default value for font_scale is 1. By increasing this value, you can increase the font size of all elements in the plot.
The following examples show how to use this syntax in practice.
Example 1: Change Font Size of All Elements in Seaborn Plot
The following code shows how to create a simple line chart in Seaborn with the default font size:
import pandas as pdimport matplotlib.pyplotas plt
import seaborn as sns
#create DataFrame
df = pd.DataFrame({'date': ['1/1/2021', '1/30/2021', '1/1/2021', '1/30/2021'],
'sales': [4, 11, 6, 18],
'company': ['A', 'A', 'B', 'B']})
#plot multiple lines
sns.lineplot(x='date', y='sales', hue='company', data=df).set(title='Sales Data')
And the following code shows how to use the sns.set() function to increase the font size of all elements in the plot:
import pandas as pdimport matplotlib.pyplotas plt
import seaborn as sns
#increase font size of all elements
sns.set(font_scale=2)
#create DataFrame
df = pd.DataFrame({'date': ['1/1/2021', '1/30/2021', '1/1/2021', '1/30/2021'],
'sales': [4, 11, 6, 18],
'company': ['A', 'A', 'B', 'B']})
#plot multiple lines
sns.lineplot(x='date', y='sales', hue='company', data=df).set(title='Sales Data')
Notice that the font size for each element in the plot has increased dramatically.
Example 2: Change Font Size of Specific Elements in Seaborn Plot
The following code shows how to change the font size of specific elements in a Seaborn plot:
import pandas as pdimport matplotlib.pyplotas plt
import seaborn as sns
#create DataFrame
df = pd.DataFrame({'date': ['1/1/2021', '1/30/2021', '1/1/2021', '1/30/2021'],
'sales': [4, 11, 6, 18],
'company': ['A', 'A', 'B', 'B']})
#plot multiple lines
sns.lineplot(x='date', y='sales', hue='company', data=df)
#modify individual font size of elements
plt.legend(title='Company', fontsize=20)
plt.xlabel('Date', fontsize=16);
plt.ylabel('Sales', fontsize=16);
plt.title('Sales Data', fontsize=20)
plt.tick_params(axis='both', which='major', labelsize=14)
Notice that each element in the plot has a unique font size based on the value specified in the fontsize argument.
Additional Resources
The following tutorials explain how to perform other common operations in Seaborn:
Cite this article
stats writer (2024). How can I change the font size in Seaborn plots?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-change-the-font-size-in-seaborn-plots/
stats writer. "How can I change the font size in Seaborn plots?." PSYCHOLOGICAL SCALES, 2 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-change-the-font-size-in-seaborn-plots/.
stats writer. "How can I change the font size in Seaborn plots?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-change-the-font-size-in-seaborn-plots/.
stats writer (2024) 'How can I change the font size in Seaborn plots?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-change-the-font-size-in-seaborn-plots/.
[1] stats writer, "How can I change the font size in Seaborn plots?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.
stats writer. How can I change the font size in Seaborn plots?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
