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

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

问题描述

我正在尝试在我的 matplotlib 图中使用字体Heuristica",但它不会显示.

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

我在 rcParameter font.serif 的第一个位置定义了Heuristica" --> 没有结果

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

我将 font.family 更改为Heuristica"并收到消息

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

findfont: FontFamily not found

这让我想到,因为 Heuristica 已安装,我可以从其他软件访问它而不会出现问题.所以我使用了 fontManager 并做了:

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)

并得到:

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

显然可以找到Heuristica.我查找了可用的 ttf-Fonts (如何在 matplotlib 中获取字体系列(或字体名称)列表)但 Heuristica 不在此列表中.

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.

推荐答案

嗯,mdboom 在 github,所有功劳归他:

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

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

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

它在您的示例中的第 4/5 行工作的原因是因为您正在从头开始创建 FontManager(它进入文件系统并搜索所有字体).在内部,当 matplotlib 稍后进行自己的字体查找时,它使用的是从 fontList.cache 文件中磁盘缓存加载的 FontManager.

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.

从长远来看,我们计划改用操作系统的字体查找机制来解决此问题(请参阅 MEP14),但与此同时,您每次需要时都需要删除 fontList.cache 文件matplotlib 以发现新字体.

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.

文件 fontList.cache 位于您的用户文件夹中 -->.matplotlib/fontList.cache,对于通常为 C:UsersyourUsername.matplotlibfontList.cache

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

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

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