Table of Contents
In order to set the tick labels font size in Matplotlib, one can use the ‘fontsize’ parameter within the tick_params() function. This parameter allows for the adjustment of the font size of the tick labels on the x-axis and y-axis. By specifying a desired font size, the tick labels can be easily customized to fit the desired visual aesthetic of the plot. This method is particularly useful for creating professional and visually appealing plots in Matplotlib.
Set Tick Labels Font Size in Matplotlib (With Examples)
You can use the following syntax to set the tick labels font size of plots in Matplotlib:
import matplotlib.pyplotas plt #set tick labels font size for both axes plt.tick_params(axis='both', which='major', labelsize=20) #set tick labels font size for x-axis only plt.tick_params(axis='x', which='major', labelsize=20) #set tick labels font size for y-axis only plt.tick_params(axis='y', which='major', labelsize=20)
The following examples show how to use this syntax in practice.
Example 1: Set Tick Labels Font Size for Both Axes
The following code shows how to create a plot using Matplotlib and specify the tick labels font size for both axes:
import matplotlib.pyplotas plt #define x and y x = [1, 4, 10] y = [5, 11, 27] #create plot of x and y plt.plot(x, y) #set tick labels font size for both axes plt.tick_params(axis='both', which='major', labelsize=20) #display plot plt.show()

Notice that we increased both the x-axis and y-axis tick labels font size.
Example 2: Set Tick Labels Font Size for X-Axis Only
The following code shows how to create a plot using Matplotlib and specify the tick labels font size for just the x-axis:
import matplotlib.pyplotas plt #define x and y x = [1, 4, 10] y = [5, 11, 27] #create plot of x and y plt.plot(x, y) #set tick labels font size for both axes plt.tick_params(axis='x', which='major', labelsize=20) #display plot plt.show()

Notice that we increased just the x-axis tick labels font size.
Example 3: Set Tick Labels Font Size for Y-Axis Only
The following code shows how to create a plot using Matplotlib and specify the tick labels font size for just the y-axis:
import matplotlib.pyplotas plt #define x and y x = [1, 4, 10] y = [5, 11, 27] #create plot of x and y plt.plot(x, y) #set tick labels font size for both axes plt.tick_params(axis='y', which='major', labelsize=20) #display plot plt.show()

Cite this article
stats writer (2024). How can I set the tick labels font size in Matplotlib?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-set-the-tick-labels-font-size-in-matplotlib/
stats writer. "How can I set the tick labels font size in Matplotlib?." PSYCHOLOGICAL SCALES, 3 May. 2024, https://scales.arabpsychology.com/stats/how-can-i-set-the-tick-labels-font-size-in-matplotlib/.
stats writer. "How can I set the tick labels font size in Matplotlib?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-set-the-tick-labels-font-size-in-matplotlib/.
stats writer (2024) 'How can I set the tick labels font size in Matplotlib?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-set-the-tick-labels-font-size-in-matplotlib/.
[1] stats writer, "How can I set the tick labels font size in Matplotlib?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, May, 2024.
stats writer. How can I set the tick labels font size in Matplotlib?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
