Matplotlib 에서 figure 에 Japanese 를 사용하면 일본어 폰트가 깨져서 한번 사용해 봤음
- TakaoPGothic font
- 기본적으로 ubuntu 에 깔려있는 폰트인 TakaoPGothic 을 사용하니 그나마 덜 깨졌음
- ipag.ttf font
- 또한 ipag.ttf 폰트를 download 하여 matplotlib.font_manager.FontProperties 로 설정한 후 text 를 적는 부분에서 fontdict={} 로 설정해주니
그나마 또한 덜 깨졌음 - ipa download 후 사용
- http://ipafont.ipa.go.jp/node72#en
- 위 사이트에서 ipa 폰트를 다운로드 해서 사용해 봤으나 이 역시 제대로 표현하지 못 함.
- 하지만 위의 3 가지 방법 역시 완벽하게 Japanese Font 를 100% 지원하지는 못 함.
- 방법이 없을까나....
- 이 방법도 한 번 해봐라
- 일본어 용으로 ubuntu keyboard input 사용하고 싶을 때 setting 하는 방법
- http://moritzmolch.com/1453
.
.
.
Linux
Install
- Make a directory under your home directory and put downloaded zip file (In this example, the file name is IPAfont00302.zip) into the directory.
$ mkdir ~/.fonts
$ cp IPAfont00302.zip ~/.fonts - Move to the directory, unzip the file, and check extracted files.
$ cd ~/.fonts
$ unzip IPAfont00302.zip
$ ls IPAfont00302 - Refresh font cache of the system.
$ fc-cache -fv
Uninstall
- Just delete these files for uninstalling IPA Font.
$ rm -r ~/.fonts/IPAfont00302
.
.
.
##
# -*- coding: utf-8 -*-
# -------- python modules --------
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime
# -------- jmlearn modules --------
import jmlearn.midend.fileutil as M
# -------- set Japanese Font --------
# 이걸 해줘야 unicode 뻑 안 나지
import sys
reload(sys)
sys.setdefaultencoding('utf-8')# TakaoGothic, TakaoPGothic, TakaoMincho# mpl.rc('font', family='Arial')
mpl.rc('font', family='Noto Sans CJK JP')
# mpl.rc('font', family='TakaoGothic')
# mpl.rc('font', family='TakaoPGothic')
# mpl.rc('font', family='Takaomincho')
# mpl.rc('font', family='Droid Sans Japanese')
# mpl.rc('font', **{'sans-serif': 'Arial', 'family': 'sans-serif'})"""Japanese Font 는 일단 다음 두 가지를 사용할 것. Font Crash 에 대해 가장 안정적이었음.
"""
font_prop = mpl.font_manager.FontProperties(fname='/home/juce/Documents/font/ipag.ttf')
# font_prop = mpl.font_manager.FontProperties(fname='/home/juce/Documents/font/IPAexfont00301/ipaexg.ttf')
.
.
.
##
# check font
font_names = []
for i, x in enumerate(mpl.font_manager.fontManager.ttflist):
print '{:3} : type - {}, font`s name - {:30}, font - {}'.format(i, type(x), x.name, x)
font_names.append(x.name)
##
# print font
font_names.sort()
for item in font_names:
print item
##
.
.
.
'Python > Matplotlib' 카테고리의 다른 글
Python | Matplotlib | Seaborn | heatmap 작업 중 Japanese font (일본어 폰트) 깨지는crash 현상 (0) | 2016.01.07 |
---|