Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib font not found

Tags:

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.

like image 212
MichaelA Avatar asked Sep 28 '14 14:09

MichaelA


People also ask

How do I add fonts to matplotlib?

Usually, double-click on the . ttf file and then click on the Install button in the window that pops up. Note that Matplotlib handles fonts in True Type Format (. ttf) , so make sure you install fonts ending in .

Where is matplotlib font cache?

It may be located under ~/. matplotlib/fontList. cache or ~/. cache/matplotlib/fontList.

What font is used in matplotlib?

Matplotlib uses DejaVu Sans in part because it includes glyphs for a very wide range of symbols, especially mathematical symbols. However in our opinion, DejaVu Sans is not very aesthetically pleasing.


1 Answers

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

like image 118
MichaelA Avatar answered Oct 01 '22 13:10

MichaelA