问题描述
我在miniconda虚拟环境中的Python 3上使用了matplotlib版本2.0.0.我正在一个没有root特权的unix科学计算集群上工作.我通常通过ipython笔记本执行python代码.如果我执行基本命令,例如:
I am using matplotlib version 2.0.0 on Python 3 in a miniconda virtual environment. I am working on a unix scientific computing cluster where I don't have root privileges. I am generally executing python code through an ipython notebook. If I do a basic command such as:
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),也可以使用
I would like to be able to use a Times New Roman font but even after deleting the Font cache file (fontList.py3k.cache) which I find from here:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
没有任何作用,我得到了与上述相同的错误.真正的字体目录:
have no effect, I get the same error as above. The true type fonts directory:
path_to_miniconda/miniconda3/envs/conda34/lib/python3.4/site-packages/matplotlib/mpl-data/fonts/ttf/
path_to_miniconda/miniconda3/envs/conda34/lib/python3.4/site-packages/matplotlib/mpl-data/fonts/ttf/
其中只有40种类型的字体:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
only has 40 fonts in it of the type: DejaVuSerif,DejaVuSans,STIX,cmb, cmt, cmy
有什么想法,怎么添加其他字体?谢谢!
Any idea what could be going on and how I can add additional fonts? Thanks!
推荐答案
对我有用:
$ sudo apt-get install msttcorefonts -qq
这篇关于Matplotlib无法找到基本字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!