jupyterで日本語
- jupyter環境では特に設定しないとグラフの日本語(軸ラベル等)が□に文字化けしてしまう。
- 日本語を表示する方法について整理
- この設定はAnacondaを使っている場合なので純粋なPythonの場合は適宜パスを読替え
Python
- matplotlib の設定ファイルを修正
~~~\Lib\site-packages\matplotlib\mpl-data\matplotlibrc
をC:\Users\~~~\.matplotlib
にコピーしてfont.family : IPAexGothic
を追記(オリジナルの設定ファイルは全ての行がコメントアウトされているので注意) - IPAexフォントを所定のフォルダに格納
格納先:C:\Users\~~~\AppData\Local\Continuum\Anaconda3\Lib\site-packages\matplotlib\mpl-data\fonts\ttf
http://ipafont.ipa.go.jp/old/ - cacheファイルを削除
C:\Users\~~~\.matplotlib\fontList.py3k.cache
- jupyter再起動
seaborn
- seaborn の設定ファイルを修正
C:\Users\~~~\AppData\Local\Continuum\Anaconda3\Lib\site-packages\seaborn\rcmod.py
- def set のfontを IPAexGothic に変更
def set(context="notebook", style="darkgrid", palette="deep", font="IPAexGothic", font_scale=1, color_codes=False, rc=None):
※ 最近のバージョン0.11.1
では def set_theme に移ったようです。内容は同じ
def set_theme(context="notebook", style="darkgrid", palette="deep", font="IPAexGothic", font_scale=1, color_codes=False, rc=None):
- def axes_style のfontを IPAexGothic に変更
# Common parameters style_dict = { "figure.facecolor": "white", "text.color": dark_gray, "axes.labelcolor": dark_gray, "legend.frameon": False, "legend.numpoints": 1, "legend.scatterpoints": 1, "xtick.direction": "out", "ytick.direction": "out", "xtick.color": dark_gray, "ytick.color": dark_gray, "axes.axisbelow": True, "image.cmap": "Greys", "font.family": ["IPAexGothic"], "font.sans-serif": ["Arial", "Liberation Sans","Bitstream Vera Sans", "sans-serif"], "grid.linestyle": "-", "lines.solid_capstyle": "round", }
R
library(repr) options(repr.plot.width=6, repr.plot.height=3) # グラフィック描画サイズの調整 windowsFonts("IPA"=windowsFont("IPAexGothic")) theme_set(theme_bw(base_size=8, base_family = 'IPA'))