2016-08-11 67 views
0

此代码Matplotlib找不到无衬线的家庭

import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import rcParams 

rcParams.update({ 
    'font.family':'sans-serif', 
    'font.sans-serif':['Helvetica'], 
    }) 

fig, ax = plt.subplots() 
im = ax.matshow(np.random.rand(16,16)) 

plt.show() 

给了我以下警告:

/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py:1288: UserWarning: 
findfont: Font family [u'sans-serif'] not found. Falling back to Bitstream Vera Sans 
(prop.get_family(), self.defaultFamily[fontext])) 

我检查了,我已经安装了黑体:

/usr/share/fonts/100dpi/helvB12.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR08.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR10.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR24-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR18.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvO18-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO24.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB18.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvO14.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB08.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB10.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB12-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB24-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB08-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB10-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB14-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR12.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR12-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO14.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR14-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR08-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR10-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvO12.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB18-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR18-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO24.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR14.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO18-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO12.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO12-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO08.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO10.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvBO14-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO08-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO10-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR24.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvB14.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvO18.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO24-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB24.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvBO24-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO08.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO10.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO12-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvBO18.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO14-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO08-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO10-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB12.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR08.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR10.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR24-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR18.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvO18-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO24.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB18.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvO14.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB08.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB10.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB12-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB24-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB08-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB10-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB14-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR12.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR12-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO14.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR14-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR08-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR10-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvO12.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB18-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR18-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO24.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR14.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO18-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO12.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO12-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO08.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO10.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvBO14-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO08-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO10-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR24.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvB14.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvO18.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO24-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB24.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvBO24-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO08.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO10.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO12-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvBO18.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO14-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO08-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO10-ISO8859-1.pcf.gz: Helvetica:style=Oblique/usr/share/fonts/100dpi/helvB12.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR08.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR10.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR24-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR18.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvO18-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO24.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB18.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvO14.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB08.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB10.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB12-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB24-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB08-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB10-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvB14-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR12.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR12-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO14.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR14-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR08-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvR10-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvO12.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB18-ISO8859-1.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvR18-ISO8859-1.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO24.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR14.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvBO18-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO12.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO12-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO08.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO10.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvBO14-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO08-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO10-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvR24.pcf.gz: Helvetica:style=Regular 
/usr/share/fonts/100dpi/helvB14.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvO18.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO24-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvB24.pcf.gz: Helvetica:style=Bold 
/usr/share/fonts/100dpi/helvBO24-ISO8859-1.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO08.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvBO10.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO12-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvBO18.pcf.gz: Helvetica:style=Bold Oblique 
/usr/share/fonts/100dpi/helvO14-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO08-ISO8859-1.pcf.gz: Helvetica:style=Oblique 
/usr/share/fonts/100dpi/helvO10-ISO8859-1.pcf.gz: Helvetica:style=Oblique 

我有也见过this post,我也一再删除fontList.cache,但无济于事。

如何将字体更改为Helvetica?

回答

0

显然这是因为我的字体是.pcf,而您需要.ttf才能真正与他们一起写字。由于许可问题,至少在Gentoo下,通过软件包管理器没有Helvetica。

我的解决方案是安装media-fonts/liberation-fonts这是解放字体的Gentoo包。 Liberation Sans是Helvetica相当不错的替身。

下面的代码段基本上固定的我的例子:

rcParams.update({ 
    'font.family':'sans-serif', 
    'font.sans-serif':['Liberation Sans'], 
    })