matplotlib 日本語設定など

投稿者: | 2021-11-29
import matplotlib

# 日本語設定のため、設定ファイルの場所を確認しておく
matplotlib.get_configdir()

# 現在のフォント確認(デフォルトは'sans-serif') 
matplotlib.rcParams['font.family']

# 日本語フォントを設定
font_options = {'family': 'Hiragino Sans'} 
plt.rc('font', **font_options)

# PDF出力時のエラー解消方法(Error「The PDF backend does not currently support 
# http://phyletica.org/matplotlib-fonts/
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42

japanize_matplotlib

  • JSON本に記載があった分
$ python -m pip install japanize_matplotlib

import japanize_matplotlib
import matplotlib.pyplot as plt