matplotlibでfontが見つからないとき

matplotlibでrcParams['font.family'] = 'serif'と設定しているのに

font family ['serif'] not found. Falling back to DejaVu Sans

とエラーが出てserif体が使えないときは、以下のようにキャッシュを消してmsttcorefontsを入れると直る。

rm -r ~/.cache/matplotlib
sudo apt install msttcorefonts -qq

https://github.com/matplotlib/matplotlib/issues/13139/ https://stackoverflow.com/questions/42097053/matplotlib-cannot-find-basic-fonts/49884009#49884009

matplotlib≥3.4からはこんなことをしなくてもよくなるらしい。 https://github.com/matplotlib/matplotlib/pull/17521