For some reason when using Times New Roman in my mpl
plots it appears bold. Other fonts are OK.
Here is a minimal example, and the result (inside a Word doc
Using python 3.7 on Windows 10, Jupyter Notebook, no Anaconda installed.
Simply adjusted the font sequence C:\Windows\Fonts\Times New Roman
as suggested above doesn't work here.
Under
C:\User\Name\.matplolib
, find a JSON File (text file) named fontlist-v300
.
Delete
{
"fname": "C:\\WINDOWS\\Fonts\\timesbd.ttf",
"name": "Times New Roman",
"style": "normal",
"variant": "normal",
"weight": "roman",
"stretch": "normal",
"size": "scalable",
"__class__": "FontEntry"
}
in the text file works for me.
Not a good way, though.
I know the question is very old, but it still is a problem, at least for me on my mac. I found a very easy solution to this problem, posted by azag0 on github
del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()
https://github.com/matplotlib/matplotlib/issues/5574
As mentioned the font selection algorithm picks the first font in the Time New Roman family, which has four different files (bold, bold italic, italic and regular). So the steps would be:
C:\Windows\Fonts\Times New Roman
I solved this problem by deleting the timesbd.tff in matplotlib/mpl-data/fonts. And I'm not sure whether timesbi.tff and timesi.tff need to be deleted, but I did it.
Digging into more details I realized that the bug is real and that mpl
is actually selecting a Times New Roman Bold font.
The font selection algorithm in font_manger.py
assigns weights on every font it finds based on the family, variant, weight, etc. (around line 1290). The "name" coming from Times New Roman Bold.ttf
is just 'Times New Roman' which might make sense, but the weight is 500, the same value as the regular font:
<Font 'Times New Roman' (Times New Roman Bold.ttf) normal normal 500 normal> with score 0.1
<Font 'Times New Roman' (Times New Roman.ttf) normal normal 500 normal> with score 0.1
On my Mac and Linux setup the bold one is encountered first and is selected by the code
if score < best_score:
best_score = score
best_font = font
I dirty patch is to replace <
by <=
...
As stated above the default font weighting is high for Times New Roman font in mpl (claim was 500 above, which I will take their word for it).
The easy fix for this is to set the weighting yourself using fontweight.
plt.xlabel('t',fontsize=32, fontname = 'Times New Roman', fontweight = 250)
This worked for me and looked normal.