Matplotlib找不到sans-serif家族

时间:2016-08-11 14:11:13

标签: matplotlib fonts gentoo

此代码

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]))

我已经检查过并且安装了Helvetica:

/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?

2 个答案:

答案 0 :(得分:0)

显然这是因为我的字体是.pcf,你需要.ttf才能真正用它们写字。由于许可问题,至少在Gentoo下,包管理器没有Helvetica可用。

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

以下代码段基本上修复了我的示例:

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

答案 1 :(得分:-1)

安装正确的ttf字体后,切记编辑anaconda3 / lib / python3.7 / site-packages / matplotlib / mpl-data / matplotlibrc(或您环境中的类似文件)。查找无衬线。取消注释此行,然后保存更改。