LoginSignup
28
27

More than 5 years have passed since last update.

matplotlibで日本語を描画 on Ubuntu

Last updated at Posted at 2016-02-22

日本語フォントが入ってることを確認(今回はTakaoPGothicを利用)

fc-list | grep Takao
/usr/share/fonts/truetype/fonts-japanese-gothic.ttf: Takao Pゴシック,TakaoPGothic:style=Regular
/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf: Takao Pゴシック,TakaoPGothic:style=Regular

フォントを設定

import matplotlib
from matplotlib.font_manager import FontProperties

font_path = '/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf'
font_prop = FontProperties(fname=font_path)
matplotlib.rcParams['font.family'] = font_prop.get_name()

f1 = plt.figure()
af1 = f1.add_subplot(111)
af1.set_title(u'たいとる')
af1.set_xlabel(u'横軸')
af1.plot([1, 2, 3, 4], label=u'えー')
af1.plot([2, 3, 3, 2], label=u'びー')
plt.legend()
plt.draw()

image

動かない時はキャッシュを削除(超重要)

rm ~/.cache/matplotlib/fontList.cache
28
27
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
28
27