我在miniconda虚拟环境中使用Python 3上的matplotlib版本2.0.0.我正在开发一个unix科学计算集群,我没有root权限.我通常通过ipython笔记本执行python代码.如果我执行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
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]))
Run Code Online (Sandbox Code Playgroud)
我希望能够使用Times New Roman字体,但即使删除了我从这里找到的字体缓存文件(fontList.py3k.cache):
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
Run Code Online (Sandbox Code Playgroud)
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
Run Code Online (Sandbox Code Playgroud)
没有效果,我得到与上面相同的错误.真正的字体类型目录:
path_to_miniconda/miniconda3/ENVS/conda34/lib中/ python3.4 /站点包/ matplotlib/MPL-数据/字体/ TTF /
其中只有40种字体:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道可能会发生什么,以及如何添加其他字体?谢谢!