Skip to content

Instantly share code, notes, and snippets.

@pastewka
Last active April 6, 2018 16:39
Show Gist options
  • Save pastewka/2293b6ec8998fc36c684 to your computer and use it in GitHub Desktop.
Save pastewka/2293b6ec8998fc36c684 to your computer and use it in GitHub Desktop.
Place fonts in $HOME/.fonts or other directory of choice.
Create file $HOME/.config/fontconfig/fonts.conf with following content:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- ~/.fonts.conf for per-user font configuration -->
<fontconfig>
<dir>~/.fonts</dir>
</fontconfig>
or add line <dir>~/.fonts</dir> to file if it exists.
Run: fc-cache --force.
Run: python3 -c "import matplotlib; print(matplotlib.get_cachedir())"
Remove the directory printed on screen.
List all fonts registered in matplotlib:
python3 -c "import matplotlib.font_manager ; matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')"
@AminFarhang
Copy link

AminFarhang commented Apr 6, 2018

Thanks for your method on matplotlib fonts.
However, I did the above procedure and consequently the ".matplotlib/fontList.json" has been updated with all fonts in my font directory but still matplotlib can not find the fonts. For example:

from matplotlib import rcParams
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = ['Alice-Regular']

I already remove the # in front of sans-serif line in "matplotlibrc" file and add the "Alice-regular" to this family font. But still it gives the following error:

/anaconda2/lib/python2.7/site-packages/matplotlib/font_manager.py:1320: UserWarning: findfont: Font family [u'sans-serif'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment