Repository navigation
Closed
Labels
Milestone
Description
Bug summary
With this in matplotlibrc:
font.sans-serif : Ubuntu
font.size : 10.0
font.weight: 300
mathtext.default : regular
I expect all text (math and regular) to be rendered with the "Ubuntu" font at a size of 10.0 and a weight of 300. This is what happens. However, when I use math text, I get this warning multiple times:
findfont: Failed to find font weight 300, now using 400.
It seems that the math text rendering machinery looks up the glyphs for the math text in a different font before looking them up in the desired font.
It would be great if the warning could specify which font is being looked up.
Code for reproduction
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams.update({
'font.sans-serif': 'Ubuntu',
'font.size': 10.0,
'font.weight': 300,
'mathtext.default': 'regular',
})
plt.figure()
plt.text(0.1, 0.5, 'Foo')
plt.text(0.2, 0.5, 'Foo $x$')
plt.show()Actual outcome
$ python mathtext.py
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
findfont: Failed to find font weight 300, now using 400.
Expected outcome
No warnings.
Additional information
No response
Operating system
Windows 11
Matplotlib Version
3.11.0
Matplotlib Backend
qtagg
Python version
3.14.6
Jupyter version
No response
Installation
pixi
Activity
subhakartadimalla commentedon Aug 3, 2026
Hi! I'd like to work on this issue. Could you please assign it to me?
QuLogic commentedon Aug 3, 2026
There is already an existing PR for this issue.
dnicolodi commentedon Aug 3, 2026
Thanks @QuLogic. #32104 addresses part of this issue. It does not address the fact that a font that is not the one that matplotlib tries to find a font that is not the one that will be used to render the text.
QuLogic commentedon Sep 4, 2026
So the handling of
mathtext.defaultis a bit strange; I can confirm that it does do what it says, but I can't figure out that path to it, since the rcParam is read in very few places. For now, I'll unlink the PR to keep this open, and will continue investigating later.QuLogic commentedon Sep 5, 2026
OK, now that we have the font family in the warning, it's a bit clearer where this is coming from. The changed font doesn't really matter; it's just the
font.weight: 300that does it:This comes from the initialization of
DejaVuFonts:matplotlib/lib/matplotlib/_mathtext.py
Lines 705 to 724 in a7db543
which is created because of the default
mathtext.fontset. This could be set to some other fontset, but cannot really be set to a custom font (despite thecustomoption) without #31064.The problem in all those cases is that we request our bundled fonts by family name only. This allows the defaults from rcParams to slip through and then the lookup searches for it in 300 weight, which doesn't exist. The easiest fix should be to force the font weight, at least until the full Unicode math font support is added.