matplotlib字体未找到 [英] matplotlib font not found

查看:256
本文介绍了matplotlib字体未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的matplotlib图中使用字体Heuristica,但它不会显示出来。

我定义了Heuristica现在在rcParameter font.serif - > no result



我把font.family改成了Heuristica,并得到了消息

  findfont:FontFamily not found 

我想,因为Heuristica已经安装了,我可以从其他软件访问它没有问题。所以我使用了fontManager,并做了:

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

得到:

  Out [7]:'C:\\Windows \\\ \\\\\\\\\\\\\\\\\\\\\' 。 
我查了可用的ttf字体(我如何获得matplotlib中的字体家族(或字体名称)的列表),但Heuristica不在此列表中。



我很乐意提供任何帮助。

解决方案

嗯,mdboom解决了 github ,所有信用都属于他:

< blockquote>

当你添加新的字体到你的系统时,你需要删除你的fontList.cache文件,以便matplotlib找到它们。

它在你的例子中的第4/5行的原因是因为你是从头开始创建一个FontManager(它出去的文件系统,追捕所有的字体)。在内部,当matplotlib稍后进行自己的字体查找时,它使用的fontManager已经从fontList.cache文件的磁盘缓存中加载。



长期来看,我们已经计划切换到使用OS的字体查找机制来解决这个问题(参见MEP14),但同时,您需要在每次要matplotlib发现新字体时删除fontList.cache文件。

文件fontList.cache位于Windows的用户文件夹 - > .matplotlib / fontList.cache中,通常为 C:\Users\yourUsername\.matplotlib\fontList.cache


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.

解决方案

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

这篇关于matplotlib字体未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆