はじめに
ubuntu20.04 on wsl2にて久々にmatplotlibを使ってグラフのプロットをする際に日本語表示ができなくなって困った際のメモ
やったこと1
こちらを参考にイチから動作確認
https://pystyle.info/japanize-matplotlib-just-by-copying-and-pasting/#outline__5
ここに書いてある通りに行うと、正しく日本語は表示された。フォントとか環境的には問題ないっぽい
やったこと2
やったこと1の操作を自分のコードに加えてみると以下のようなメッセージが表示されてNG
.... RuntimeWarning: Glyph 27 missing from current font
これは自分のコードになにか問題があると確信した。取り急ぎ以下を確認
linux$ file myplotsample.py
Python script, ASCII text executable
あれ、UTF-8になっていない。これはまずいかも、ということで以下の操作を実行。
linux$ nkf -w --overwrite myplotsample.py
linux$ file myplotsample.py
Python script, UTF-8 Unicode text executable
これにて問題は解消され、所望の日本語表示ができた。
まとめ
文字コードは念のため確認すべきと反省。エディタの設定がまずかったのかも…