findfont: Generic family 'sans-serif' not found because none of the following families were found: Montserrat

Viewed 16

I'm trying to use one of the Google fonts in my MatPlotLib project. It's called 'Montserrat' (you can see it here)

My short example Python program is throwing the following message:

findfont: Generic family 'sans-serif' not found because none of the following families were found: Montserrat

test.py

import matplotlib as mpl
import matplotlib.font_manager
import matplotlib.pyplot as plt

mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = ['Montserrat']

x = [2001, 2002, 2003]
y = [2001, 2002, 2003]

index = x
width = 0.50

fig, ax = plt.subplots()
rects = plt.bar(index, y, width)

plt.savefig('example.svg', bbox_inches = 'tight', transparent=True)

The program runs and outputs a chart, but the font message is frustrating.

I read somewhere that MatPlotLib uses the font cache. Check this out. The font is present. For good measure, I tried copying the font to another locations on my drive: /usr/local/share/fonts. I was careful to make the file perms the same as the parent (root). Once I moved it, fc-list detected the fonts.

$ fc-list | grep -i Montserrat
/home/myname/.local/share/fonts/Montserrat_100italic.ttf: Montserrat,Montserrat Thin:style=Thin Italic,Italic
/home/myname/.local/share/fonts/Montserrat_900italic.ttf: Montserrat,Montserrat Black:style=Black Italic,Italic
/home/myname/.local/share/fonts/Montserrat_200italic.ttf: Montserrat,Montserrat ExtraLight:style=ExtraLight Italic,Italic
/home/myname/.local/share/fonts/Montserrat_700.ttf: Montserrat:style=Bold
/home/myname/.local/share/fonts/Montserrat_500italic.ttf: Montserrat,Montserrat Medium:style=Medium Italic,Italic
/home/myname/.local/share/fonts/Montserrat_800italic.ttf: Montserrat,Montserrat ExtraBold:style=ExtraBold Italic,Italic
/home/myname/.local/share/fonts/Montserrat_italic.ttf: Montserrat:style=Italic
/home/myname/.local/share/fonts/Montserrat_100.ttf: Montserrat,Montserrat Thin:style=Thin,Regular
/home/myname/.local/share/fonts/Montserrat_600italic.ttf: Montserrat,Montserrat SemiBold:style=SemiBold Italic,Italic
/home/myname/.local/share/fonts/Montserrat_regular.ttf: Montserrat:style=Regular
/home/myname/.local/share/fonts/Montserrat_900.ttf: Montserrat,Montserrat Black:style=Black,Regular
/home/myname/.local/share/fonts/Montserrat_500.ttf: Montserrat,Montserrat Medium:style=Medium,Regular
/home/myname/.local/share/fonts/Montserrat_600.ttf: Montserrat,Montserrat SemiBold:style=SemiBold,Regular
/home/myname/.local/share/fonts/Montserrat_700italic.ttf: Montserrat:style=Bold Italic
/home/myname/.local/share/fonts/Montserrat_300.ttf: Montserrat,Montserrat Light:style=Light,Regular
/home/myname/.local/share/fonts/Montserrat_300italic.ttf: Montserrat,Montserrat Light:style=Light Italic,Italic
/home/myname/.local/share/fonts/Montserrat_800.ttf: Montserrat,Montserrat ExtraBold:style=ExtraBold,Regular
/home/myname/.local/share/fonts/Montserrat_200.ttf: Montserrat,Montserrat ExtraLight:style=ExtraLight,Regular

I'm at a loss of what to do to fix this.

Where does MatPlotLib actually look for the fonts?

0 Answers
Related