【发布时间】:2017-06-25 02:56:18
【问题描述】:
我在 miniconda 虚拟环境中的 Python 3 上使用 matplotlib 2.0.0 版。我正在开发一个没有 root 权限的 unix 科学计算集群。我通常通过 ipython notebook 执行 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']
没有效果,我得到与上面相同的错误。真字体目录:
path_to_miniconda/miniconda3/envs/conda34/lib/python3.4/site-packages/matplotlib/mpl-data/fonts/ttf/
只有40种字体类型:DejaVuSerif,DejaVuSans,STIX,cmb, cmt, cmy
知道会发生什么以及如何添加其他字体吗?谢谢!
【问题讨论】:
-
我遇到了同样的问题。感谢您的提示 fm.get_cachedir(),我正在擦除错误的缓存,现在它可以工作了!谢谢你:)
-
我有同样的错误,但我的数字最终是衬线字体(使用乳胶)。
-
尝试重装,matplotlib 2018年发布第三版
标签: python matplotlib truetype miniconda