TheChymera
TheChymera

Reputation: 17934

Matplotlib cannot find sans-serif family

This code

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

gives me the following warning:

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

I have checked and I have Helvetica installed:

/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

I have also seen this post, and I have repeatedly deleted fontList.cache, but to no avail.

How can I change my font to Helvetica?

Upvotes: 2

Views: 7397

Answers (1)

TheChymera
TheChymera

Reputation: 17934

Apparently this was because my fonts were .pcf and you need .ttf to actually write with them. due to licensing issues, at least under Gentoo, there is no Helvetica available via the package manager.

My solution was to install media-fonts/liberation-fonts which is the Gentoo package for the Liberation Fonts. Liberation Sans is a fairly good stand-in for Helvetica.

The following code snippet basically fixed my example:

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

Upvotes: 2

Related Questions