11_matplotlibrc_한글_처리 - smart1004/doc GitHub Wiki

[ruser01@workbench_p /]$ cd /home/common/anaconda3/lib/python3.5/site-packages/matplotlib/mpl-data/ [ruser01@workbench_p mpl-data]$ ls fonts images matplotlibrc sample_data stylelib

vim matplotlibrc font.family : NanumGothic # kyung_ook modyfied. for solving korean font error. 18.11.03 #font.style : normal

minus 깨짐 해결

axes.unicode_minus : False # use unicode for the minus symbol ### kyung_ook modyfied. for solving minus font error. 18.11.03

파이썬에서 한글

http://egloos.zum.com/timebird/v/7309990

솔직히 나는 한글문제에는 둔감한 편이다. 프로그래밍에서 문자보다는 숫자를 다루는 일도 많고 한글처리에 신경를 쓸 바엔 아예 영어로 처리하는 게 편리해서이다. 그러나 내가 아닌 타인의 편의를 위해서는 한글을 다뤄야 한다. 그런데 matplotlib을 이용하여 한글이 포함된 그림을 그리는 경우 다음과 같은 깍두기 문자가 나온다.

이것은 한글처리의 문제라기보다 한글이 없는 영문 font가 기본으로 적용되기 때문이다. 다음은 해결방법중 하나이다.

  1. 명령 프롬프트를 연다
  2. RC 파일 위치를 찾는다

Python 3.6.0 |Anaconda 4.3.0 (32-bit)| (default, Dec 23 2016, 12:06:52) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.

import matplotlib matplotlib.matplotlib_fname() 'C:\Users\Administrator\Anaconda3\lib\site-packages\matplotlib\mpl-data\matplotlibrc' quit()

  1. 이 파일을 메모장으로 연다. C:> notepad C:\Users\Administrator\Anaconda3\Lib\site-packages\matplotlib\mpl-data\matplotlibrc

윈도우

matplotlib.matplotlib_fname()

'/home/common/anaconda3/lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc'

matplotlibrc 파일을 수정한다.

  1. font.family 부분을 '나눔 고딕(영문으로 NanumGothic)'으로 설정한다.

#font.family : sans-serif font.family : NanumGothic #font.style : normal

minus 깨짐 해결

axes.unicode_minus : False # use unicode for the minus symbol

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 또는 RC파일을 수정하지 않고 소스코드차원에서 다음과 같이 할 수도 있다.

from matplotlib import font_manager, rc ... font_name = font_manager.FontProperties(fname="c:/Windows/Fonts/malgun.ttf").get_name() rc('font', family=font_name)