小编loo*_*oom的帖子

Matplotlib rcParams 无法识别“Times New Roman”(mac High Sierra)

我正在尝试将 matplotlib 图的字体设置为 Times New Roman。我努力了:

import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'Times New Roman'
Run Code Online (Sandbox Code Playgroud)

我相信这是设置字体的正确方法,但我不断收到此错误,提示找不到找到的字体:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py:1238: UserWarning: findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans.
Run Code Online (Sandbox Code Playgroud)

经过一番搜索,我确认我已经下载了该字体。我尝试打开 python shell 并亲自检查 rcParams 的内容。在一堆其他字体参数中,我好奇地得到了一个font.serif包含 Times New Roman 的字体列表。

          'font.serif': ['DejaVu Serif',
                         '比特流维拉衬线',
                         “计算机现代罗马”,
                         《新世纪教科书》,
                         《世纪教科书L》,
                         “乌托邦”,
                         “ITC 布克曼”,
                         ‘书人’,
                         'Nimbus Roman No9 L',
                         '英语字体格式一种',
                         《时代》,
                         '帕拉蒂诺',
                         '宪章',
                         '衬线'],

但是,font.family仅包含一项:sans-serif,而matplotlib 文档指出内应有五个值font.family。以前有人遇到过这个错误吗?你怎么修好它的?

python fonts matplotlib

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

fonts ×1

matplotlib ×1

python ×1