본문 바로가기
딥러닝/설정

matplotlib 한글 폰트 사용(windows, anaconda)

by 배우고 성장하는 청년 블로그 2021. 1. 18.

1. 현재 폰트 설정 디렉토리 확인

  import matplotlib

  matplotlib.matplotlib_fname()

2. 1.에서 확인한 디렉토리로 이동

 

3. 이동한 디렉토리 내에서 "matplotlibrc" 파일 실행 (ex: 메모장, 노트패드)

 

4. "matplotlibrc" 파일에서 Ctrl + f 로 font.family를 검색하여 변경해주기

  #font.family: normal -> font.family: NanumBarunGothic(원하는 폰트)

"matplotlibrc" 파일

5. "anaconda3/lib/site-packages/matplotlib/mpl-data/fonts/ttf"에 원하는 폰트파일 넣기

-> 나눔바른고딕 폰트파일 URL: software.naver.com/software/summary.nhn?softwareId=GWS_000240#

 

나눔바른고딕

네이버의 나눔바른고딕 폰트

software.naver.com

6. 현재 넣은 폰트파일과 "matplotlibrc" 파일에 적은 폰트이름과 같은 지 확인 (생략가능)

 from matplotlib import font_manager, rc

 font_path = "사용자/anaconda3/lib/site-packages/matplotlib/mpl-data/fonts/ttf/폰트파일명.ttf"

 font_name = font_manager.FontProperties(fname=font_path).get_name()

 print(font_name) 

 

-> 출력과 font.family 뒤에 넣은 폰트명과 같은 지 확인

 

7. 현재 jupyter notebook에서 사용하는 캐쉬 파일이 있는 곳 이동

-> matplotlib.get_cachedir() 으로 출력하여 확인할 수 있다.

-> "tex.cahe" 폴더 & "fontlist-xxx.json" 파일 등 삭제

 

8. jupyter notebook 재실행