如何修复 matplotlib findfont: Font family 'xkcd' not found on Ubuntu 22.04+

问题:

使用 matplotlib 绘制 XKCD 风格图时,你会看到以下错误消息:

install_humor_sans.sh
findfont: Font family 'xkcd' not found.
findfont: Font family 'xkcd Script' not found.
findfont: Font family 'Comic Neue' not found.
findfont: Font family 'Comic Sans MS' not found.

解决方案

使用以下命令安装 Humor Sans 字体

install_humor_sans.sh
sudo apt -y install font-humor-sans

此外,你需要删除 matplotlib 字体缓存:

clear_matplotlib_font_cache.sh
rm -rf ~/.cache/matplotlib

Check out similar posts by category: Linux, Python