matplotlib + 한글 (Ubuntu Linux)

matplotlib + 한글 (Ubuntu Linux)

  • 사용가능한 폰트 확인, TTF 폰트 설치 방법
  • matplotlib 텍스트 출력시 폰트 특성을 지정 (FontProperties)
  • matplotlib 전역으로 한글 글꼴 지정(rcParams)

2017 FinanceData http://facebook.com/financedata

In [1]:
%matplotlib inline

기본정보 확인

In [2]:
# 실행중인 운영체제 확인

import platform
platform.platform()
Out[2]:
'Linux-4.9.17-c9-x86_64-with-Ubuntu-14.04-trusty'
In [3]:
# 파이썬 버전

import sys
sys.version_info
Out[3]:
sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)
In [4]:
# matplotlib 주요 설치 정보

import matplotlib

print ('버전: ', matplotlib.__version__)
print ('설치위치: ', matplotlib.__file__)
print ('설정: ', matplotlib.get_configdir())
print ('캐시: ', matplotlib.get_cachedir())
버전:  2.0.2
설치위치:  /usr/local/lib/python3.4/dist-packages/matplotlib/__init__.py
설정:  /home/ubuntu/.config/matplotlib
캐시:  /home/ubuntu/.cache/matplotlib

한글이 포함된 간단한 차트

In [19]:
import numpy as np

data = np.random.randint(-100, 100, 50).cumsum()
data
Out[19]:
array([ -15,   26,   66,    2,   46,  -49,  -96, -117,  -95,  -13,   20,
        102,  193,  284,  293,  241,  338,  384,  449,  463,  513,  432,
        339,  359,  326,  290,  238,  238,  209,  167,  251,  196,  227,
        208,  252,  324,  348,  431,  372,  296,  307,  381,  399,  321,
        375,  416,  403,  480,  498,  537])
In [20]:
import matplotlib.pyplot as plt

plt.plot(range(50), data, 'r')
plt.title('가격변동 추이')
plt.ylabel('가격')
plt.show()

한글이 제대로 표시되지 않는다. 한글 폰트가 설치되어 있지 않거나, 한글 폰트를 사용하도록 설정되어 있지 않은 경우이다.

우분투에 폰트는 /usr/share/fonts/ 디렉토리에 있다.

In [7]:
ls -l /usr/share/fonts/
total 12
drwxr-xr-x 2 root root 4096 Nov  1  2016 cmap/
drwxr-xr-x 3 root root 4096 Aug  7 05:12 truetype/
drwxr-xr-x 3 root root 4096 Nov  1  2016 type1/
In [8]:
ls -l /usr/share/fonts/truetype/
total 4
drwxr-xr-x 2 root root 4096 Nov  1  2016 dejavu/

글꼴 설치

2012년 부터 우분투에는 나눔글꼴이 기본 포함되어 있다.

만일, 나눔 글꼴이 설치되어 있지 않다면 다음과 같이 설치할 수 있으며, 다른 ttf 폰트도 /usr/share/fonts/ 폴더에 복사하여 사용할 수 있다.

나눔 글꼴 설치

apt-get 명령으로 나눔글꼴(fonts-nanum)을 설치하고, fc-cache 명령으로 폰트 캐시 삭제

$ sudo apt-get install fonts-nanum*
$ sudo fc-cache -fv

만일 다른 ttf 폰트를 가져왔다면 다음과 같이 복사하고, fc-cache 명령으로 폰트 캐시 삭제

$ sudo cp new_font.ttf /usr/share/fonts/
$ sudo fc-cache -fv

matplotlib 나눔 글꼴을 추가

나눔 글꼴을 matplotlib 에 복사하고, matplotlib의 폰트 캐시를 삭제

$ sudo cp /usr/share/fonts/truetype/nanum/Nanum* /usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/
$ rm -rf /home/ubuntu/.cache/matplotlib/*

나눔(nanum) 글꼴이 설치된 것을 확인

In [21]:
ls -l /usr/share/fonts/truetype/
total 12
drwxr-xr-x 2 root root 4096 Nov  1  2016 dejavu/
drwxr-xr-x 2 root root 4096 Aug  7 05:17 nanum/
drwxr-xr-x 2 root root 4096 Aug  7 05:17 nanum-eco/
In [22]:
ls -l /usr/share/fonts/truetype/nanum/
total 46880
-rw-r--r-- 1 root root 4186072 Dec 28  2013 NanumBarunGothic.ttf
-rw-r--r-- 1 root root 4415956 Dec 28  2013 NanumBarunGothicBold.ttf
-rw-r--r-- 1 root root 3745376 Dec 28  2013 NanumBrush.ttf
-rw-r--r-- 1 root root 4343844 Dec 28  2013 NanumGothic.ttf
-rw-r--r-- 1 root root 4288380 Dec 28  2013 NanumGothicBold.ttf
-rw-r--r-- 1 root root 4171172 Dec 28  2013 NanumGothicExtraBold.ttf
-rw-r--r-- 1 root root 1523188 Dec 28  2013 NanumGothicLight.ttf
-rw-r--r-- 1 root root 2315924 May  5  2010 NanumGothic_Coding.ttf
-rw-r--r-- 1 root root 2246240 May  5  2010 NanumGothic_Coding_Bold.ttf
-rw-r--r-- 1 root root 3808496 Dec 28  2013 NanumMyeongjo.ttf
-rw-r--r-- 1 root root 4638736 Dec 28  2013 NanumMyeongjoBold.ttf
-rw-r--r-- 1 root root 4748088 Dec 28  2013 NanumMyeongjoExtraBold.ttf
-rw-r--r-- 1 root root 3548656 Dec 28  2013 NanumPen.ttf

사용 가능한 ttf 폰트 목록

사용가능한 ttf(true type font)폰트 목록은 다음 리스트로 간단하게 얻을 수 있다

matplotlib.font_manager.fontManager.ttflist
In [23]:
import matplotlib
import matplotlib.font_manager

[f.fname for f in matplotlib.font_manager.fontManager.ttflist]
Out[23]:
['/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono-Bold.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/cmex10.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/cmr10.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizFiveSymReg.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSerif-Bold.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizOneSymBol.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSerif-Italic.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXNonUniBol.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizFourSymBol.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXGeneralBol.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizThreeSymReg.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXNonUniBolIta.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizTwoSymReg.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXGeneralBolIta.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/cmss10.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizThreeSymBol.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSerifDisplay.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXGeneralItalic.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/cmb10.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXNonUniIta.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXGeneral.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizFourSymReg.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansDisplay.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/cmmi10.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSerif.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/cmsy10.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans-BoldOblique.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono-Oblique.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono-BoldOblique.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/cmtt10.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXNonUni.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSerif-BoldItalic.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizOneSymReg.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/STIXSizTwoSymBol.ttf',
 '/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans-Oblique.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-BoldItalic.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothic_Coding.ttf',
 '/usr/share/fonts/truetype/nanum/NanumMyeongjoBold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumBarunGothicBold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothicLight.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Bold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothicBold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Oblique.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Italic.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEcoBold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumMyeongjo.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Bold.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoExtraBold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumPen.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothicExtraBold.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoBold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-BoldOblique.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf',
 '/usr/share/fonts/truetype/nanum/NanumBrush.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEco.ttf',
 '/usr/share/fonts/truetype/nanum/NanumMyeongjoExtraBold.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEcoExtraBold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothic.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothic_Coding_Bold.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumGothicEco.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed.ttf']

사용가능한 폰트 목록 중 나눔글꼴(이름에 'Nanum'이 포함된) 폰트 목록만 추출

In [24]:
import matplotlib
import matplotlib.font_manager

[f.name for f in matplotlib.font_manager.fontManager.ttflist if 'Nanum' in f.name]
Out[24]:
['NanumGothicCoding',
 'NanumMyeongjo',
 'NanumBarunGothic',
 'NanumBarunGothic',
 'NanumGothic',
 'NanumGothic',
 'NanumMyeongjo Eco',
 'NanumMyeongjo',
 'NanumGothic Eco',
 'Nanum Pen Script',
 'NanumGothic',
 'NanumGothic Eco',
 'Nanum Brush Script',
 'NanumMyeongjo Eco',
 'NanumMyeongjo',
 'NanumMyeongjo Eco',
 'NanumGothic',
 'NanumGothicCoding',
 'NanumGothic Eco']
In [25]:
[(f.name, f.fname) for f in matplotlib.font_manager.fontManager.ttflist if 'Nanum' in f.name]
Out[25]:
[('NanumGothicCoding',
  '/usr/share/fonts/truetype/nanum/NanumGothic_Coding.ttf'),
 ('NanumMyeongjo', '/usr/share/fonts/truetype/nanum/NanumMyeongjoBold.ttf'),
 ('NanumBarunGothic',
  '/usr/share/fonts/truetype/nanum/NanumBarunGothicBold.ttf'),
 ('NanumBarunGothic', '/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf'),
 ('NanumGothic', '/usr/share/fonts/truetype/nanum/NanumGothicLight.ttf'),
 ('NanumGothic', '/usr/share/fonts/truetype/nanum/NanumGothicBold.ttf'),
 ('NanumMyeongjo Eco',
  '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEcoBold.ttf'),
 ('NanumMyeongjo', '/usr/share/fonts/truetype/nanum/NanumMyeongjo.ttf'),
 ('NanumGothic Eco',
  '/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoExtraBold.ttf'),
 ('Nanum Pen Script', '/usr/share/fonts/truetype/nanum/NanumPen.ttf'),
 ('NanumGothic', '/usr/share/fonts/truetype/nanum/NanumGothicExtraBold.ttf'),
 ('NanumGothic Eco',
  '/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoBold.ttf'),
 ('Nanum Brush Script', '/usr/share/fonts/truetype/nanum/NanumBrush.ttf'),
 ('NanumMyeongjo Eco',
  '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEco.ttf'),
 ('NanumMyeongjo',
  '/usr/share/fonts/truetype/nanum/NanumMyeongjoExtraBold.ttf'),
 ('NanumMyeongjo Eco',
  '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEcoExtraBold.ttf'),
 ('NanumGothic', '/usr/share/fonts/truetype/nanum/NanumGothic.ttf'),
 ('NanumGothicCoding',
  '/usr/share/fonts/truetype/nanum/NanumGothic_Coding_Bold.ttf'),
 ('NanumGothic Eco', '/usr/share/fonts/truetype/nanum-eco/NanumGothicEco.ttf')]

폰트를 지정하는 두가지 방법

matplotlib에서 폰트를 지정하여 출력하는 하는 대표적인 방법은 크기 두 가지이다.

  1. 텍스트 출력시 폰트 특성을 지정: FontProperties 속성으로 폰트 속성을 지정
  2. 전역으로 지정: rcParams 을 사용하여 전역으로 설정값을 지정

텍스트 출력시 폰트 특성을 지정

텍스트를 출력하는 다음 함수들을 사용할 때, fontproperties 인자에 폰트를 지정할 수 있다.

matplotlib.pyplot

  • title()
  • xlabel()
  • ylabel()
  • legend()
  • text()

matplotlib.axes

  • set_title()

예를 들어, 다음과 같이 텍스트와 폰트를 지정하여 출력할 수 있다.

  • plt.text(0, 0, "Sample Text", fontproperties=fontprop)
In [26]:
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

path = '/usr/share/fonts/truetype/nanum/NanumMyeongjo.ttf'
fontprop = fm.FontProperties(fname=path, size=18)

plt.plot(range(50), data, 'r')
plt.title('가격변동 추이', fontproperties=fontprop)
plt.ylabel('가격', fontproperties=fontprop)
plt.show()
In [27]:
# TTF폰트 파일을 직접 지정하는 방법 (나눔 펜 글씨)

import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

path_gothic = '/usr/share/fonts/truetype/nanum/NanumGothic.ttf'
fontprop1 = fm.FontProperties(fname=path_gothic, size=20)

path_pen = '/usr/share/fonts/truetype/nanum/NanumPen.ttf'
fontprop2 = fm.FontProperties(fname=path_pen, size=34)

plt.plot(range(50), data, 'r')
plt.ylabel('가격', fontproperties=fontprop1)
plt.title('가격변동 추이', fontproperties=fontprop2)
plt.show()
In [28]:
path = '/usr/share/fonts/truetype/nanum/NanumGothic_Coding.ttf'
prop = fm.FontProperties(fname=path, size=18)

fig, ax = plt.subplots()
ax.plot(data)
ax.set_title('가격 변화 (나눔고딕코딩)', fontproperties=prop)

plt.show()

폰트가 항상 '/usr/share/fonts'에 있어야 하는 것은 아니다.

ttf 폰트 파일을 복사해서 바로 사용할 수 도 있다. 현재 디렉토리에 MalgunGothic.ttf 파일을 복사하여 다음과 같이 ttf 파일을 지정하여 사용할 수 있다.

In [29]:
ll MalgunGothic.ttf
-rw-r--r-- 1 ubuntu 3997212 Aug  7 04:22 MalgunGothic.ttf
In [30]:
import matplotlib.font_manager as fm

fontprop = fm.FontProperties(fname="./MalgunGothic.ttf", size=24)

plt.title('맑은고딕 제목', fontproperties=fontprop)
plt.plot(data)
plt.show()

전역 글꼴 설정: matplotlib.rcParams[]

matplotlib.rcParams을 통해 matplotlib의 다양한 설정값을 읽거나 지정할 수 있다.

https://matplotlib.org/users/customizing.html

In [31]:
# 기본 설정 읽기
import matplotlib.pyplot as plt

# size, family
print (plt.rcParams['font.size'] ) 
print (plt.rcParams['font.family'] )
10.0
['sans-serif']
In [32]:
# serif, sans-serif, monospace
print (plt.rcParams['font.serif']) 
print (plt.rcParams['font.sans-serif']) 
print (plt.rcParams['font.monospace']) 
['DejaVu Serif', 'Bitstream Vera Serif', 'Computer Modern Roman', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif']
['DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif']
['DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Computer Modern Typewriter', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace']

폰트의 기본값들을 다음과 같이 설정할 수 있다

In [33]:
import matplotlib.pyplot as plt

plt.rcParams["font.family"] = 'NanumGothicCoding'
plt.rcParams['font.size'] = 12.
plt.rcParams['xtick.labelsize'] = 24.
plt.rcParams['ytick.labelsize'] = 24.
plt.rcParams['axes.labelsize'] = 20.

plt.title('가격의 변화')
plt.plot(range(50), data, 'r')
plt.show()
In [34]:
import matplotlib.pyplot as plt

plt.rcParams["font.family"] = 'NanumGothicCoding'
plt.rcParams["font.size"] = 12
plt.rcParams["figure.figsize"] = (14,4)

plt.title('가격의 변화')
plt.plot(range(50), data, 'r')
plt.show()

레이블에 '-'가 있는 경우 유니코드의 '-'문자를 그대로 출력하면 '-' 부호만 깨져 보인다. 이를 방지하기 위해 'axes.unicode_minus' 옵션을 False로 지정한다.

In [35]:
import matplotlib.pyplot as plt

plt.rcParams["font.family"] = 'NanumGothicCoding'
plt.rcParams["font.size"] = 12
plt.rcParams['xtick.labelsize'] = 12.
plt.rcParams['ytick.labelsize'] = 12.
plt.rcParams["figure.figsize"] = (14,4)
plt.rcParams['axes.grid'] = True 
plt.rcParams['axes.unicode_minus'] = False

plt.title('가격의 변화')
plt.plot(range(50), data, 'r')
plt.show()

ttf 파일에서 폰트 이름 얻어 전역 설정

"font.family"에 지정할 이름을 .ttf 파일로 부터 얻을 수 있다

In [36]:
from matplotlib import font_manager, rc

font_fname = '/usr/share/fonts/truetype/nanum/NanumGothic.ttf'
font_name = font_manager.FontProperties(fname=font_fname).get_name()

rc('font', family=font_name)
print(font_name)
NanumGothic

(참고) 시스템에 설치된 글꼴 확인

우분투에 설치되어 있는 글꼴 목록은 fc-list 명령어로 볼 수 있다.

In [37]:
# 전체 글꼴(460여개)중 처음 10개만 출력

! fc-list | head -10 
Fontconfig warning: ignoring C.UTF-8: not a valid language tag
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book
/usr/share/fonts/truetype/nanum/NanumGothic_Coding.ttf: NanumGothicCoding,나눔고딕코딩:style=Regular
/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
/usr/share/fonts/truetype/nanum/NanumGothicExtraBold.ttf: NanumGothic,나눔고딕,NanumGothicExtraBold,나눔고딕 ExtraBold:style=ExtraBold,Regular,Bold
/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEco.ttf: NanumMyeongjo Eco,나눔명조 에코:style=Regular
/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoBold.ttf: NanumGothic Eco,나눔고딕 에코:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-BoldItalic.ttf: DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold Italic,Bold Italic
/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf: DejaVu Sans,DejaVu Sans Light:style=ExtraLight
/usr/share/fonts/type1/gsfonts/n021024l.pfb: Nimbus Roman No9 L:style=Medium Italic
In [38]:
# 한글 글꼴만 보려면 ':lang=ko' 옵션을 지정
# 한글 글꼴 전체(약 50여개)에서 .ttf 만 출력

! fc-list :lang=ko | grep ttf
Fontconfig warning: ignoring C.UTF-8: not a valid language tag
/usr/share/fonts/truetype/nanum/NanumGothic_Coding.ttf: NanumGothicCoding,나눔고딕코딩:style=Regular
/usr/share/fonts/truetype/nanum/NanumGothicExtraBold.ttf: NanumGothic,나눔고딕,NanumGothicExtraBold,나눔고딕 ExtraBold:style=ExtraBold,Regular,Bold
/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEco.ttf: NanumMyeongjo Eco,나눔명조 에코:style=Regular
/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoBold.ttf: NanumGothic Eco,나눔고딕 에코:style=Bold
/usr/share/fonts/truetype/nanum/NanumGothicLight.ttf: NanumGothic,나눔고딕,NanumGothic Light,나눔고딕 Light:style=Light,Regular
/usr/share/fonts/truetype/nanum/NanumBrush.ttf: Nanum Brush Script,나눔손글씨 붓:style=Regular
/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf: NanumBarunGothic,나눔바른고딕:style=Regular
/usr/share/fonts/truetype/nanum/NanumGothic.ttf: NanumGothic,나눔고딕:style=Regular
/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoExtraBold.ttf: NanumGothic Eco,나눔고딕 에코,NanumGothic Eco ExtraBold,나눔고딕 에코 ExtraBold:style=ExtraBold,Regular
/usr/share/fonts/truetype/nanum/NanumBarunGothicBold.ttf: NanumBarunGothic,나눔바른고딕:style=Bold
/usr/share/fonts/truetype/nanum/NanumPen.ttf: Nanum Pen Script,나눔손글씨 펜:style=Regular
/usr/share/fonts/truetype/nanum/NanumGothicBold.ttf: NanumGothic,나눔고딕:style=Bold
/usr/share/fonts/truetype/nanum-eco/NanumGothicEco.ttf: NanumGothic Eco,나눔고딕 에코:style=Regular
/usr/share/fonts/truetype/nanum/NanumMyeongjoExtraBold.ttf: NanumMyeongjo,나눔명조,NanumMyeongjoExtraBold,나눔명조 ExtraBold:style=ExtraBold,Regular
/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEcoBold.ttf: NanumMyeongjo Eco,나눔명조 에코:style=Bold
/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEcoExtraBold.ttf: NanumMyeongjo Eco,나눔명조 에코,NanumMyeongjo Eco ExtraBold,나눔명조 에코 ExtraBold:style=ExtraBold,Regular
/usr/share/fonts/truetype/nanum/NanumGothic_Coding_Bold.ttf: NanumGothicCoding,나눔고딕코딩:style=Bold
/usr/share/fonts/truetype/nanum/NanumMyeongjo.ttf: NanumMyeongjo,나눔명조:style=Regular
/usr/share/fonts/truetype/nanum/NanumMyeongjoBold.ttf: NanumMyeongjo,나눔명조:style=Bold

참고

In [39]:
# 사용가능한 시스템의 TTF 폰트 목록
import matplotlib.font_manager as font_manager

font_list = font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
print(len(font_list))
font_list
40
Out[39]:
['/usr/share/fonts/truetype/nanum/NanumGothicExtraBold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-BoldOblique.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Oblique.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-BoldItalic.ttf',
 '/usr/share/fonts/truetype/nanum/NanumBrush.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothic_Coding.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf',
 '/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothic_Coding_Bold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Italic.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEcoExtraBold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Bold.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoBold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumPen.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothic.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumGothicEco.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed-Bold.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEcoBold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumMyeongjoExtraBold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothicBold.ttf',
 '/usr/share/fonts/truetype/nanum/NanumMyeongjoBold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerifCondensed.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Oblique.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-BoldOblique.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf',
 '/usr/share/fonts/truetype/nanum/NanumMyeongjo.ttf',
 '/usr/share/fonts/truetype/nanum/NanumBarunGothicBold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSerif-BoldItalic.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumMyeongjoEco.ttf',
 '/usr/share/fonts/truetype/nanum/NanumGothicLight.ttf',
 '/usr/share/fonts/truetype/nanum-eco/NanumGothicEcoExtraBold.ttf',
 '/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf']
In [40]:
# matplotlib 설정 파일의 위치

matplotlib.matplotlib_fname()
Out[40]:
'/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/matplotlibrc'
In [41]:
# 캐쉬 디렉토리

matplotlib.get_cachedir()
Out[41]:
'/home/ubuntu/.cache/matplotlib'

댓글

Comments powered by Disqus