Matplotlib: Times New Roman appears bold

后端 未结 8 1726
醉梦人生
醉梦人生 2021-02-14 23:40

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

8条回答
  •  情歌与酒
    2021-02-15 00:11

    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:

     with score 0.1
     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 <=...

提交回复
热议问题