Python 如何在matplotlib中使用幽默SAN?

Python 如何在matplotlib中使用幽默SAN?,python,matplotlib,ubuntu-18.04,Python,Matplotlib,Ubuntu 18.04,我想用matploblib创建一个ROC曲线的XKCD样式图。它基本上工作正常,但我不明白为什么它不使用幽默。它肯定安装在我的系统上: $ fc-list | grep -i humor /home/user/.local/share/fonts/Humor-Sans.ttf: Humor Sans:style=Regular 如何使matplotlib使用幽默无字体 我已经尝试添加fontname='Humor Sans': 我的代码 当前结果 Matplotlib单独拥有自己的缓存文件。在

我想用matploblib创建一个ROC曲线的XKCD样式图。它基本上工作正常,但我不明白为什么它不使用幽默。它肯定安装在我的系统上:

$ fc-list | grep -i humor
/home/user/.local/share/fonts/Humor-Sans.ttf: Humor Sans:style=Regular
如何使matplotlib使用幽默无字体

我已经尝试添加fontname='Humor Sans':

我的代码 当前结果
Matplotlib单独拥有自己的缓存文件。在我的系统上,我可以通过执行

mv ~/.cache/matplotlib/fontList.json ~/.cache/matplotlib/fontList-backup.json

您可以通过以下方式强制重建字体缓存:

import matplotlib.font_manager
matplotlib.font_manager._rebuild()
然后检查字体可用性

matplotlib.font_manager.findfont('Humor Sans')

删除字体列表缓存实际上会强制重新生成字体缓存。我不认为我发布的答案更合适,因为它使用了private _-rebuild方法,但这就对了。
import matplotlib.font_manager
matplotlib.font_manager._rebuild()
matplotlib.font_manager.findfont('Humor Sans')