Usign Latex fonts as recommended here throws a Warning:
findfont: Font family ['serif'] not found. Falling back to DejaVu Sans.
findfont: Generic family 'serif' not found because none of the following families were found:
Code for reproduction
importmatplotlib.pyplotaspltplt.rcParams.update({
"font.family": "serif",
# Use LaTeX default serif font."font.serif": [],
# Use specific cursive fonts."font.cursive": ["Comic Neue", "Comic Sans MS"],
})
plt.figure()
plt.plot([1,2,3,4])
plt.savefig('test.png')
plt.savefig('test.pgf')
I'm not sure why the example was designed in this way.. if the fonts were available you should've got a PGF/PDF with these fonts:
pdffonts pgf_fonts.pdf name type encoding emb sub uni object ID------------------------------------ ----------------- ---------------- --- --- --- ---------BXGEVL+DejaVuSerif Type 3 Custom yes yes no 52 0GCWXDV+DejaVuSans-Oblique Type 3 Custom yes yes no 23 0FJGZKM+DejaVuSansMono Type 3 Custom yes yes no 40 0BMQQDV+DejaVuSans Type 3 Custom yes yes no 28 0TVXSBT+ComicNeue-Regular Type 3 Custom yes yes no 15 0
However, with the current example; serif font-family isn't found (because the list is essentially empty!); this is what you get:
$ pdffonts pgf_fonts.pdf name type encoding emb sub uni object ID------------------------------------ ----------------- ---------------- --- --- --- ---------BMQQDV+DejaVuSans Type 3 Custom yes yes no 28 0GCWXDV+DejaVuSans-Oblique Type 3 Custom yes yes no 23 0FJGZKM+DejaVuSansMono Type 3 Custom yes yes no 51 0TVXSBT+ComicNeue-Regular Type 3 Custom yes yes no 15 0
Note the missing serif font...
Fix is pretty simple, something like:
import matplotlib.pyplot as plt
plt.rcParams.update({
+ # Use LaTeX default serif font-family.+ # https://matplotlib.org/stable/tutorials/text/usetex.html#sphx-glr-tutorials-text-usetex-py
"font.family": "serif",
- # Use LaTeX default serif font.- "font.serif": [],
# Use specific cursive fonts.
"font.cursive": ["Comic Neue", "Comic Sans MS"],
})
Adding documentation tag since the example itself is slightly incorrect.
[...]
It's really overriding the default Matplotlib serif font-family as an empty list; whereas it really should've been untouched
The empy list is suggested here: https://matplotlib.org/stable/tutorials/text/pgf.html (section "Font specification"). So, either this is correct or that section of the documentation should also be modified. In any case,
The sentence "You can also use the LaTeX default Computer Modern fonts by clearing the lists for rcParams["font.serif"]" is currently not correct since the code:
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
FranzForstmayr commented on Aug 17, 2021
Similar to #13139
aitikgupta commented on Aug 29, 2021
Adding documentation tag since the example itself is slightly incorrect..
When you did:
It's really overriding the default Matplotlib serif font-family as an empty list; whereas it really should've been untouched (i.e., the defaults mentioned at: https://matplotlib.org/stable/tutorials/text/usetex.html#sphx-glr-tutorials-text-usetex-py)
I'm not sure why the example was designed in this way.. if the fonts were available you should've got a PGF/PDF with these fonts:
However, with the current example; serif font-family isn't found (because the list is essentially empty!); this is what you get:
Note the missing serif font...
Fix is pretty simple, something like:
import matplotlib.pyplot as plt plt.rcParams.update({ + # Use LaTeX default serif font-family. + # https://matplotlib.org/stable/tutorials/text/usetex.html#sphx-glr-tutorials-text-usetex-py "font.family": "serif", - # Use LaTeX default serif font. - "font.serif": [], # Use specific cursive fonts. "font.cursive": ["Comic Neue", "Comic Sans MS"], })You're welcome to create a PR :)
FranzForstmayr commented on Aug 30, 2021
I'll go for it
Fix matplotlib#20850
urrameu commented on Sep 6, 2021
The empy list is suggested here: https://matplotlib.org/stable/tutorials/text/pgf.html (section "Font specification"). So, either this is correct or that section of the documentation should also be modified. In any case,
Revert "Fix matplotlib#20850"
Fix matplotlib#20850
oscargus commented on Jan 5, 2022
That seems to be correct if the pgf backend is used. However, in https://matplotlib.org/stable/gallery/userdemo/pgf_fonts.html pdf is not used. Adding
import matplotlib as mpl mpl.use("pgf")first in the example file may help. (I'll add a PR.)
oscargus commented on Jan 5, 2022
Wasn't that easy...
The sentence "You can also use the LaTeX default Computer Modern fonts by clearing the lists for rcParams["font.serif"]" is currently not correct since the code:
matplotlib/lib/matplotlib/backends/backend_pgf.py
Lines 47 to 55 in 68d6b79
will use the default Matplotlib font instead.
(Unless pdflatex is used, in which case the fonts are not set.)
So, I've changed this to
path = pathlib.Path(fm.findfont(family), fallback_to_default=False)which then will not set it to the default font. Not sure if it will break anything else.
github-actions commented on Jul 13, 2026
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!