Pythonの代表的なグラフ描写モジュールmatplotlib
でグラフタイトルや凡例に日本語を使う方法をメモります。
環境:
OS: macOS High Sierra 10.13.3
Python: Python3.6
基本的には, 以下のサイトを参考にすれば上手くいくと思いますが
/usr/local/lib/python3.6/site-packages/matplotlib/font_manager.py:1320: UserWarning: findfont: Font family ['IPAexGothic'] not found. Falling back to DejaVu Sans (prop.get_family(), self.defaultFamily[fontext]))
というエラーが起きてしまいました。
上記のサイトでも言われている通り,~/.matplotlib
内の
casheファイルfontList.py3k.cache
を削除しても同様のエラーは消えず。。。
結論としては, 同ディレクトリ内のfont-listファイルfontList.json
も削除する必要がありました。
削除した後で, matplotlibで描写をさせると
/usr/local/lib/python3.6/site-packages/matplotlib/font_manager.py:281: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. 'Matplotlib is building the font cache using fc-list. '
という表示が。
しばらく待つと新しいfont-listファイルが作成されて,
無事に日本語が表示されました。
めでたし。