我正在使用Python 3中的matplotlib版本2.0.0,位于miniconda虚拟环境中。我正在一个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']
没有效果,我得到了与上面相同的错误。TrueType字体目录:
path_to_miniconda/miniconda3/envs/conda34/lib/python3.4/site-packages/matplotlib/mpl-data/fonts/ttf/
只有40种字体类型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy。
有什么想法是怎么回事以及我如何添加其他字体?谢谢!