LoginSignup
65
58

More than 5 years have passed since last update.

Jupyterで日本語ラベルを使ったグラフを描画する

Last updated at Posted at 2015-03-08

IPython Notebook、デフォルト状態ではグラフ中の日本語ラベルが豆腐になるので設定ファイルで日本語フォントを指定して使っている人が多いと思う。しかしIPythonを3にアップデートしたらIPython NotebookがJupyterになり、日本語が再び豆腐になってしまった。

どうやら設定ファイルの構成が変わった様で、既存のProfileをそのまま使えなくなった。ipython_*_config.pyファイルは既存と同じ名前の物でもデフォルトの内容が変わっているので、Profileごと作り直した方が良さそう。

Jupyterの設定ファイル

IPython 3.x系ではIPython 2.x系の ipython_notebook_config.pyipython_kernel_config.pyipython_notebook_config.py に分かれた模様。

Matplotlibで日本語ラベルを使いたい場合は ipython_kernel_config.py に書く必要がある。

ipython_kernel_config.py
c.InlineBackend.rc = {
    'font.size': 11,
    'font.family': 'Osaka',
    'figure.figsize': (6.0, 4.0),
    'savefig.dpi': 80,
    'axes.titlesize': 12
}

c.InlineBackend.figure_formats = set(['png', 'retina'])

これで日本語ラベルが使える。

スクリーンショット 2015-03-08 23.29.49.png

設定値の確認

Jupyter上で

import matplotlib
matplotlib.rcParams.get('font.family')

利用可能なフォント一覧は

import matplotlib.font_manager as fm
fm.findSystemFonts()

で得られる。

65
58
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
65
58