Skip to content

Instantly share code, notes, and snippets.

@yamakk
Created September 27, 2011 23:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yamakk/1246530 to your computer and use it in GitHub Desktop.
matplotlibで日本語フォントを使うサンプル
#coding:utf-8
"""
matplotlibで日本語フォントを使うサンプル
"""
import matplotlib.pyplot
import matplotlib.font_manager
# for Mac
font_path = '/Library/Fonts/Osaka.ttf'
# for Linux
#font_path = '/home/k01/.fonts/ipag00303/ipag.ttf'
# font_pathが見つからない場合
# RuntimeError: Could not open facefile
# /home/k01/.fonts/ipag00303/ipag.ttf; Cannot_Open_Resource になる
font_prop = matplotlib.font_manager.FontProperties(fname=font_path)
matplotlib.pyplot.title(u'日本語のテストタイトル', fontproperties=font_prop)
matplotlib.pyplot.plot(range(10))
# matplotlib.pyplot.show()だと日本語は正しく表示されない savefigはOK
matplotlib.pyplot.savefig('test.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment