How to change the font size on a matplotlib plot
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Matplotlib, font size is not a single setting. Titles, axis labels, tick labels, legends, and annotations can each have their own font size, and the best approach depends on whether you want to style one plot or set a default for many plots.
Change Font Size Per Plot Element
The most direct approach is to set font size where you create each element.
This is the most explicit solution and is usually best when only one figure needs customization.
Change Tick Label Font Size
Tick labels have their own setting.
Or more completely:
This is a common detail people miss when they change title and axis label sizes but forget the tick labels.
Set Global Defaults With rcParams
If you want all plots in a script or notebook to use larger fonts, change Matplotlib defaults.
Now every later plot in that session uses those defaults unless overridden.
This is the right answer when consistent styling matters across many figures.
Use plt.rc_context For Temporary Defaults
Sometimes you want global-looking defaults, but only for one block of code.
This is useful in shared notebooks where you do not want to permanently change the plotting environment.
Legends, Text, And Annotations
Legends and free text have their own font controls too.
So if a plot still looks inconsistent after changing the obvious settings, check whether annotations or legends are still using defaults.
Object-Oriented API Is Easier To Maintain
You can set font sizes through plt.title(...) and similar stateful helpers, but the object-oriented style is clearer for nontrivial plots.
This becomes especially helpful once you have multiple axes in one figure.
Apply A Consistent Style Across Subplots
When a figure has several subplots, repeat the same font policy on each axis instead of styling them one by one in an ad hoc way.
This keeps dashboards and comparison figures readable without relying on hidden global state.
Common Pitfalls
The most common mistake is changing only the title font size and forgetting tick labels, legend text, or annotations.
Another mistake is mixing global rcParams tweaks with local overrides and then losing track of why different plots look inconsistent.
Developers also sometimes call plt.xticks(fontsize=...) in one place and tick_params in another without a clear style policy.
Finally, if you are working in notebooks, remember that rcParams changes persist in the session until you reset them or restart the kernel.
Summary
- Set
fontsizedirectly on titles, labels, legends, and text for per-plot control. - Use
tick_params(labelsize=...)for tick labels. - Use
rcParamswhen you want consistent defaults across many plots. - Use
plt.rc_contextfor temporary styling scopes. - Check every text element, not just the title, when adjusting readability.

