Change fonts in Matplotlib by setting the font name before you plot
Matplotlib uses a default font that works everywhere but looks plain. You can change it to any font your computer has installed by adding one line of code before you create your chart. The simplest method is to set matplotlib.rcParams, which tells Matplotlib what font to use for all text in that script.
Open your Python file and add this line near the top, after your import statements:
import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['Arial'] plt.plot([1, 2, 3], [1, 4, 9]) plt.show()
Replace 'Arial' with any font name your system has. Common options are 'Times New Roman', 'Courier New', 'Verdana', or 'Georgia'. The font applies to all text in your figure — titles, axis labels, and legend text — unless you override it for a specific element.
Key Takeaways
- Use plt.rcParams['font.sans-serif'] = ['FontName'] to change the default font for your entire script.
- You can change the font size at the same time with plt.rcParams['font.size'] = 12, where 12 is the size in points.
- To change the font for only one text element, pass the fontname parameter directly to that function, like plt.title('My Title', fontname='Arial').
- If Matplotlib cannot find your font, it falls back to the default; check that the font name matches exactly what your operating system calls it.
Change the font for the whole script with rcParams
The rcParams dictionary holds Matplotlib's settings. When you change a value in rcParams, that change applies to every plot you create in that script after the change. This is the fastest way if you want one font throughout your work.
Add these lines after your imports and before any plotting code:
import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['Arial'] plt.rcParams['font.size'] = 12
The first line sets the font family. The second line sets the default size in points. Both explore to titles, labels, and legend text. If you want to use a serif font instead of sans-serif, change the key to plt.rcParams['font.serif'] and list serif fonts like 'Times New Roman' or 'Georgia'.
Change the font for one specific text element
Sometimes you want one title in Arial and another in Courier, or you want the axis labels in a different size than the legend. Pass the font settings directly to the function that creates that text.
For a title:
plt.title('Sales by Quarter', fontname='Arial', fontsize=14)
For axis labels:
plt.xlabel('Month', fontname='Times New Roman', fontsize=11) plt.ylabel('Revenue', fontname='Times New Roman', fontsize=11)
For a legend:
plt.legend(fontsize=10, prop={'family': 'Courier New'})
These overrides explore only to that one element. Everything else still uses the default font you set in rcParams, or Matplotlib's built-in default if you did not change rcParams.
Find out what fonts your computer has available
Matplotlib can only use fonts that your operating system has installed. If you type a font name that does not exist, Matplotlib will not warn you — it will silently use the default font instead. To see which fonts are available, run this code:
import matplotlib.font_manager as fm fonts = sorted([f.name for f in fm.fontManager.ttf_fonts]) for font in fonts: print(font)
This prints a list of every font Matplotlib can find on your system. Look for the exact name — 'Arial' and 'arial' are the same font, but 'Ariel' (misspelled) will not work. On Windows, common fonts include Arial, Times New Roman, Courier New, Calibri, and Verdana. On Mac, you also have Helvetica, Garamond, and Palatino. On Linux, the available fonts depend on what you have installed.
Use a font file directly if the font is not installed
If you have a font file on your computer but it is not installed system-wide, you can point Matplotlib to the file directly. This is useful if you downloaded a custom font or work with fonts that are not part of your operating system.
First, find the full path to your font file. On Windows, it might be C:\Users\YourName\Downloads\myfont.ttf. On Mac or Linux, it might be /Users/YourName/Downloads/myfont.ttf or /home/username/Downloads/myfont.ttf.
Then use this code:
from matplotlib import font_manager as fm font_path = '/path/to/your/font.ttf' font = fm.FontProperties(fname=font_path) plt.title('My Title', fontproperties=font)
This loads the font from the file and applies it only to that title. If you want to use the same custom font throughout your script, load it once and reuse the font object for every text element.
Troubleshoot when your font does not appear
The most common reason a font does not show up is a typo in the name. Matplotlib does not error when it cannot find a font — it just uses the default. Check that your font name matches exactly what appears in the list from fm.fontManager.ttf_fonts.
If you are using a font file and it still does not work, make sure the path is correct. Use forward slashes even on Windows, or use a raw string: r'C:\Users\YourName\Downloads\myfont.ttf'. If the file is in the same folder as your script, you can use just the filename: 'myfont.ttf'.
On some systems, Matplotlib caches the font list. If you installed a new font and it does not appear, try restarting Python or clearing the cache by deleting the folder at ~/.matplotlib (on Mac or Linux) or %APPDATA%\matplotlib (on Windows).
Frequently Asked Questions
Can I use a font that is not installed on my computer?
Yes, if you have the font file (usually a .ttf file). Use fm.FontProperties(fname='path/to/font.ttf') to load it and pass it to any text function with the fontproperties parameter. This works for custom or downloaded fonts.
What is the difference between font.sans-serif and font.serif?
Sans-serif fonts like Arial have no decorative lines at the ends of letters. Serif fonts like Times New Roman have small lines. Use plt.rcParams['font.sans-serif'] for clean, modern charts and plt.rcParams['font.serif'] for formal or traditional ones. Both take a list of font names.
How do I change the font size without changing the font family?
Use plt.rcParams['font.size'] = 12 to change the default size in points. Or pass fontsize=12 to individual functions like plt.title('Title', fontsize=14). Larger numbers make text bigger; typical sizes range from 8 to 16 points.
Why does my font look different in the saved image than on screen?
Matplotlib may use a different font when saving to PDF or EPS if the font is not embedded. For PNG or JPG, the font should match what you see. If you need exact font control in a saved file, use plt.savefig('file.png', dpi=300) with a high DPI, or save as PDF and embed fonts with plt.rcParams['pdf.fonttype'] = 42.
Can I use multiple fonts in the same chart?
Yes. Set a default font in rcParams, then override it for specific elements. For example, use Arial for the title and Times New Roman for the axis labels by passing fontname to each function separately. This gives you fine control over which text uses which font.