Mic*_*elA 18 python fonts matplotlib
我正在尝试在matplotlib图中使用字体"Heuristica",但它不会显示出来.
我在rcParameter font.serif的第一个地方定义了"Heuristica" - >没有结果
我将font.family改为"Heuristica"并得到了消息
findfont: FontFamily not found
Run Code Online (Sandbox Code Playgroud)
这让我思考,因为安装了Heuristica,我可以毫无问题地从其他软件访问它.所以我使用了fontManager并做了:
import pylab as pl
la = pl.matplotlib.font_manager.FontManager()
lu = pl.matplotlib.font_manager.FontProperties(family = 'Heuristica')
la.findfont(lu)
Run Code Online (Sandbox Code Playgroud)
得到了:
Out[7]: 'C:\\Windows\\Fonts\\Heuristica-Regular.otf'
Run Code Online (Sandbox Code Playgroud)
所以很明显可以找到Heuristica.我查找了可用的ttf-Fonts(如何获取matplotlib中的字体系列列表(或字体名称))但是Heuristica不在此列表中.
任何帮助我都会很高兴.
Mic*_*elA 35
好吧,mdboom在github上解决了这个问题,所有的功劳都属于他:
向系统添加新字体时,需要删除fontList.cache文件才能使matplotlib找到它们.
它在你的例子中在第4/5行上工作的原因是因为你是从头开始创建一个FontManager(它转到文件系统并搜索所有字体).在内部,当matplotlib稍后进行自己的字体查找时,它使用的是已从fontList.cache文件中的磁盘缓存加载的FontManager.
从长远来看,我们计划转而使用操作系统的字体查找机制来解决这个问题,(参见MEP14),但与此同时,每当你想让matplotlib发现时你都需要删除fontList.cache文件新字体.
文件fontList.cache位于您的用户文件夹 - > .matplotlib/fontList.cache,对于Windows通常是 C:\Users\yourUsername\.matplotlib\fontList.cache
| 归档时间: |
|
| 查看次数: |
15793 次 |
| 最近记录: |