Table of Contents
Seaborn is a popular data visualization library in Python that allows users to create visually appealing and informative plots. One of the key features of Seaborn is its ability to adjust the number of ticks on the x and y axes of a plot. Ticks are the small marks or labels on the axes that represent specific data points. To adjust the number of ticks in Seaborn plots, users can use the “set_xticks” and “set_yticks” functions and specify the desired number of ticks as a parameter. Additionally, users can also customize the tick labels and their spacing using the “set_xticklabels” and “set_yticklabels” functions. These functions provide users with the flexibility to fine-tune their plots and present data in a more precise and visually appealing manner.
Adjust Number of Ticks in Seaborn Plots
You can use the following basic syntax to specify the positions and labels of axis ticks on plots:
#specify x-axis tick positions and labels plt.xticks([1, 2, 3], ['A', 'B', 'C']) #specify y-axis tick positions and labels plt.yticks([4, 5, 6], ['D', 'E', 'F'])
The following examples show how to use this syntax in practice.
Example 1: Set Axis Tick Positions
The following code shows how to create a simple scatterplot using seaborn:
import pandas as pd import matplotlib.pyplotas plt import seaborn as sns #create DataFrame df = pd.DataFrame({'var1': [25, 12, 15, 14, 19, 23, 25, 29], 'var2': [5, 7, 7, 9, 12, 9, 9, 4]}) #create scatterplot sns.scatterplot(data=df, x='var1', y='var2')

By default, seaborn chooses an optimal number of ticks to display on both the x-axis and y-axis.
However, we can use the following code to specify the number of ticks and their exact positions on each axis:
import pandas as pd import matplotlib.pyplotas plt import seaborn as sns #create DataFrame df = pd.DataFrame({'var1': [25, 12, 15, 14, 19, 23, 25, 29], 'var2': [5, 7, 7, 9, 12, 9, 9, 4]}) #create scatterplot sns.scatterplot(data=df, x='var1', y='var2') #specify positions of ticks on x-axis and y-axis plt.xticks([15, 20, 25]) plt.yticks([4, 8, 12])

Example 2: Set Axis Tick Positions & Labels
The following code shows how to create a scatterplot and specify both the axis tick positions and the tick labels:
import pandas as pd import matplotlib.pyplotas plt import seaborn as sns #create DataFrame df = pd.DataFrame({'var1': [25, 12, 15, 14, 19, 23, 25, 29], 'var2': [5, 7, 7, 9, 12, 9, 9, 4]}) #create scatterplot sns.scatterplot(data=df, x='var1', y='var2') #specify positions of ticks on x-axis and y-axis plt.xticks([15, 20, 25], ['A', 'B', 'C']) plt.yticks([4, 8, 12], ['Low', 'Medium', 'High'])

Note: Refer to to see how to change just the axis labels.
Cite this article
stats writer (2024). How can the number of ticks in Seaborn plots be adjusted?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-number-of-ticks-in-seaborn-plots-be-adjusted/
stats writer. "How can the number of ticks in Seaborn plots be adjusted?." PSYCHOLOGICAL SCALES, 6 May. 2024, https://scales.arabpsychology.com/stats/how-can-the-number-of-ticks-in-seaborn-plots-be-adjusted/.
stats writer. "How can the number of ticks in Seaborn plots be adjusted?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-number-of-ticks-in-seaborn-plots-be-adjusted/.
stats writer (2024) 'How can the number of ticks in Seaborn plots be adjusted?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-number-of-ticks-in-seaborn-plots-be-adjusted/.
[1] stats writer, "How can the number of ticks in Seaborn plots be adjusted?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, May, 2024.
stats writer. How can the number of ticks in Seaborn plots be adjusted?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
