我在 miniconda 虚拟环境中的 Python 3 上使用 matplotlib 版本 2.0.0。我正在开发一个 UNIX 科学计算集群,但我没有 root 权限。我通常通过 ipython 笔记本执行 python 代码。如果我执行一个基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一条错误消息:
path_to_miniconda/miniconda3/envs/conda34/lib/python3.4/site-
packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family
['sans-serif'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
我希望能够使用 Times New Roman 字体,但即使删除了我从这里找到的字体缓存文件(fontList.py3k.cache):
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
没有效果,我得到与上面相同的错误。 true type 字体目录:
path_to_miniconda/miniconda3/envs/conda34/lib/python3.4/site-packages/matplotlib/mpl-data/fonts/ttf/
只有 40 种字体类型:DejaVuSerif、DejaVuSans、STIX、cmb、cmt、cmy
知道会发生什么以及如何添加其他字体吗?谢谢!