1
2

More than 3 years have passed since last update.

matplotlibで日本語フォントを使うには

Last updated at Posted at 2020-11-29

ちょっと調べたら「matplotlibrcの書き換え」とか、沢山方法はあるみたいですが、なんだか面倒だったので一番簡単かと思われる方法をメモしておきます。

ttfファイルのダウンロード

IPAexフォント/IPAフォント
準備として、例えば上のようなサイトとかからTTFフォントのファイルをダウンロードします。

設定

試しに、簡単な折れ線グラフにラベルをつけてみます。

%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties


font_path= "ttfファイルのPATH"
font_prop =matplotlib.font_manager.FontProperties(fname=font_path,size=20)

x = [1,2, 3, 4, 5]
y = [5, 1, 3, 2, 4]


plt.xlabel('xラベル',fontproperties=font_prop)
plt.ylabel('yラベル',fontproperties=font_prop)
plt.plot(x, y)
plt.show()

image.png

参考

matplotlibで日本語フォントを使うサンプル
matplotlibで日本語

1
2
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
1
2