On both my Mac and Linux setup (mpl 1.5.0) is appears that the bold version is selected over the regular one, as both are understood to have the same weight.
See this question on StackOverflow where I described the problem and the "solution".
#5414, while not ready immediately, should address this by using font-config rather than our own homegrown code for font lookup. That's our long term solution to these sorts of problems, but won't be ready until at least matplotlib 2.1, maybe later.
As for the actual problem at hand, I'm having trouble reproducing it. With the Times New Roman Bold that ships with Win8 (which has the filename timesbd.ttf and has the md5 hash 43a1861fb747438005fa1615b70798a4), the "style_flags" metadata is set correctly to indicate that it is bold. In the linked SO question the filename appears to be "Times New Roman Bold.ttf", so maybe that's a different font from a different source?
I recently started seeing this problem on OSX as well. The default Times fonts are named: Time New Roman.ttf, Time New Roman Bold.ttf, etc. The answer in the linked SO post seems to work, however, is there a better temporary solution to this?
I experienced the same problem. In font_manager.py the weight is set by scanning the font properties from sfnt4 = sfnt.get((1,0,0,4)) in the weight_dict.
Since the sfnt4 is "Times New Roman Bold" and the weight dict contains also "roman" as a valid weight, all Fonts containing "Roman" in this string will be set to a weight of 500, regardless of the "bold".
On simple solution is to remove "roman" from the weight_dict. Ideally would be a more sophisticated method to scan.
I started seeing this same problem recently, when I upgraded from matplotlib 1.5 to 2.0
(MacBook Pro 2012 with macOS 10.12.5, python.org's framework installation of Python 3.6.1)
(azag0's fix works for me)
This is happening for me with Matplotlib 2.2.2 on a Windows 10 machine. I assume there is no global fix to this solution other than the adding the local code provided by azag0.
This code returns "KeyError: 'roman'"every time I run it and I would like to find a way to fit it without the error showing up.
I upgraded from Python 3.5.4 with matplotlib 2.0.2 to Python 3.7.1 with matplotlib 3.0.2 and this was suddenly a problem. The local fix works. I'm on Windows 7.
Same here when upgrading from 3.0.3 to 3.10.0.
The answer
del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()
did NOT solve the problem. Instead it completely crashed my fontmanager, raising several errors. Unluckily I had a deadline pressuring me to get back to work asap, thus I did not have the time to write down everything.
I had to re-install my whole anaconda dist, clearing all users/.matplotlib, users/.conda etc folders to make it work again. Additionally since then, the 'Times' font can't be found and instead of using 'Times New Roman', it is falling back to sans-serif DejaVu Sans...
Activity
mdboom commented on Nov 27, 2015
#5414, while not ready immediately, should address this by using font-config rather than our own homegrown code for font lookup. That's our long term solution to these sorts of problems, but won't be ready until at least matplotlib 2.1, maybe later.
As for the actual problem at hand, I'm having trouble reproducing it. With the Times New Roman Bold that ships with Win8 (which has the filename timesbd.ttf and has the md5 hash 43a1861fb747438005fa1615b70798a4), the "style_flags" metadata is set correctly to indicate that it is bold. In the linked SO question the filename appears to be "Times New Roman Bold.ttf", so maybe that's a different font from a different source?
ferdinandvanwyk commented on Feb 22, 2017
I recently started seeing this problem on OSX as well. The default Times fonts are named: Time New Roman.ttf, Time New Roman Bold.ttf, etc. The answer in the linked SO post seems to work, however, is there a better temporary solution to this?
steffen-micdev commented on Apr 21, 2017
I experienced the same problem. In font_manager.py the weight is set by scanning the font properties from sfnt4 = sfnt.get((1,0,0,4)) in the weight_dict.
Since the sfnt4 is "Times New Roman Bold" and the weight dict contains also "roman" as a valid weight, all Fonts containing "Roman" in this string will be set to a weight of 500, regardless of the "bold".
On simple solution is to remove "roman" from the weight_dict. Ideally would be a more sophisticated method to scan.
jhrmnn commented on May 5, 2017
Just encountered this problem as well. It can be fixed locally with
perwin commented on Jun 20, 2017
I started seeing this same problem recently, when I upgraded from matplotlib 1.5 to 2.0
(MacBook Pro 2012 with macOS 10.12.5, python.org's framework installation of Python 3.6.1)
(azag0's fix works for me)
Datseris commented on Oct 10, 2017
Just chiming in to say that this is happening also to me, in Windows 10, with matplotlib 2.0 and anaconda, python 3.6
Edit: I confirm that the answer by azag0 works, i.e.
xchank commented on Apr 2, 2018
Windows 10 with matplotlib 2.1.2 and anaconda
The answer by azag0 works like a charm
austindowney commented on Aug 23, 2018
This is happening for me with Matplotlib 2.2.2 on a Windows 10 machine. I assume there is no global fix to this solution other than the adding the local code provided by azag0.
This code returns "KeyError: 'roman'"every time I run it and I would like to find a way to fit it without the error showing up.
tcanders commented on Dec 10, 2018
I upgraded from Python 3.5.4 with matplotlib 2.0.2 to Python 3.7.1 with matplotlib 3.0.2 and this was suddenly a problem. The local fix works. I'm on Windows 7.
perwin commented on Mar 1, 2019
This problem re-appeared when I upgraded to matplotlib 3.0.2 (macOS 10.13.6, Python.org's Python 3.7.2); azag0's fix worked again.
JoElfner commented on Jun 7, 2019
Same here when upgrading from 3.0.3 to 3.10.0.
The answer
did NOT solve the problem. Instead it completely crashed my fontmanager, raising several errors. Unluckily I had a deadline pressuring me to get back to work asap, thus I did not have the time to write down everything.
I had to re-install my whole anaconda dist, clearing all users/.matplotlib, users/.conda etc folders to make it work again. Additionally since then, the 'Times' font can't be found and instead of using 'Times New Roman', it is falling back to sans-serif DejaVu Sans...
iTomxy commented on Jan 11, 2021
I fixed this by changing importing :
and it works
when using jhrmnn's method, I got error :
my codes:
any help ?