34

I'm trying to use the font "Heuristica" in my matplotlib plots, but it won't show up.

I defined "Heuristica" on the first spot in the rcParameter font.serif --> no result

I changed font.family to "Heuristica" and got the message

findfont: FontFamily not found

that got me thinking, because Heuristica is installed and I can access it from other software without problems. So I used the fontManager and did:

import pylab as pl
la = pl.matplotlib.font_manager.FontManager()
lu = pl.matplotlib.font_manager.FontProperties(family = 'Heuristica')
la.findfont(lu)

and got:

Out[7]: 'C:\\Windows\\Fonts\\Heuristica-Regular.otf'

So obviously Heuristica can be found. I looked up the available ttf-Fonts (How can i get list of font family(or Name of Font) in matplotlib) but Heuristica is not in this list.

I'd be glad about any help.

6
  • What version of mpl are you using? Commented Sep 28, 2014 at 16:10
  • I am using Version 1.3.1 Commented Sep 28, 2014 at 17:16
  • try updating to 1.4.0. If that does not work please make an issue on github Commented Sep 28, 2014 at 17:17
  • 2
    The problem persist under 1.4.0. Are you sure that is really an issue for Github and not an issue with the person in front of my PC? Regarding a github issue: May I link to this question or do I a copy & paste? Commented Sep 28, 2014 at 18:31
  • Please put enough information is the issue that we don't have to link back to SO. Questions here are not stable (both due to edits and deletions). Please include enough detail that someone with a windows machine can reproduce it (including if you have changed your rcparam file and the full traceback). Commented Sep 28, 2014 at 21:36

2 Answers 2

58

Well, mdboom solved the problem over at github, all the credit belongs to him:

When you add new fonts to your system, you need to delete your fontList.cache file in order for matplotlib to find them.

The reason it works on lines 4/5 in your example is because you are creating a FontManager from scratch (which goes out to the filesystem and hunts down all the fonts). Internally, when matplotlib later does its own font lookup, it is using a FontManager that has been loaded from a cache on disk in the fontList.cache file.

Long term, we have plans to switch to using the font lookup mechanisms of the OS to get around this problem, (see MEP14), but in the meantime, you'll need to remove the fontList.cache file everytime you want matplotlib to discover new fonts.

The file fontList.cache is located at your Userfolder --> .matplotlib/fontList.cache, for Windows that would normally be C:\Users\yourUsername\.matplotlib\fontList.cache

Sign up to request clarification or add additional context in comments.

9 Comments

~/.cache/matplotlib on Ubuntu.
I tried the solution only on windows and can't test on Linux. But maybe you want to add something to the github Issue, which is probably the best way to get a bugfix: github.com/matplotlib/matplotlib/issues/3590
I also had to delete fontList.json.
Forcing matplotlib to rebuild the cache is probably the most cross-platform solution with import matplotlib.font_manager as font_manager; font_manager._rebuild()
For me the file was called fontlist-v330.json
|
5

For some versions of Matplotlib, it may be necessary to clear the LRU cache of _get_fontconfig_fonts() (next to removing the fontList.cache file).

fm = matplotlib.font_manager
fm._get_fontconfig_fonts.cache_clear()

This function is responsible for calling, and caching, fc-list on a Linux/Unix system. If your font appears in fc-list, and not in Matplotlib's fonts, even after removing the fontList.cache file, this may be the culprit.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.