Created
September 27, 2011 23:17
-
-
Save yamakk/1246530 to your computer and use it in GitHub Desktop.
matplotlibで日本語フォントを使うサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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