0
0

More than 3 years have passed since last update.

matplotlibで日本語表示ができなくなって困った件

Last updated at Posted at 2021-08-09

はじめに

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

これにて問題は解消され、所望の日本語表示ができた。

まとめ

文字コードは念のため確認すべきと反省。エディタの設定がまずかったのかも…

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0