matplotlib(WSL)

インストール

$ conda install matplotlib

日本語化

Google Nato Fontsを使います。

$ cd
$ mkdir downloads
$ cd downloads
$ wget https://noto-website-2.storage.googleapis.com/pkgs/Noto-unhinted.zip
$ unzip Noto-unhinted.zip
$ sudo mkdir -p /usr/share/fonts/opentype/noto
$ sudo cp *.otf *.ttf /usr/share/fonts/opentype/noto
$ sudo chmod 644 /usr/share/fonts/opentype/noto/*.ttf
$ sudo chmod 644 /usr/share/fonts/opentype/noto/*.otf
$ fc-cache -f -v

$ cd
$ mkdir -p .config/matplotlib
$ cd .config/matplotlib
$ cp ../../miniconda3/lib/python3.1/site-packages/matplotlib/mpl-data/matplotlibrc ./

matplotlibrc にフォントを設定する

font.serif:Noto Serif CJK JP
font.sans-serif:Noto Sans CJK JP

cacheファイルがあれば削除。
Linuxの場合、フォルダ .cacheにある。

Qt環境変数

.bashrc末尾に追加

export QT_QPA_PLATFORM=xcb

テスト

import matplotlib.pyplot as plt
plt.title('今日はいい天気!')
plt.show()

タイトルとURLをコピーしました