matplotlib 한글 깨짐 처리
matplotlib 실행 시 한글 깨짐 오류 메시지
---------------------------------------------------------------------------------------------------------------------------------
findfont: Font family ['san-serif'] not found. Falling back to DejaVu Sans.
/home/user/.local/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 51064 missing from current font.
font.set_text(s, 0.0, flags=flags)
---------------------------------------------------------------------------------------------------------------------------------
우분투 20.04 LTS 폰트 설치 위치
/usr/share/fonts/
나눔 폰트 설치 위치
/usr/share/fonts/truetype/nanum/
아래 1 또는 2 중에서 선택하여 적용
1. matplotlibrc 수정
$ cd /python3 설치 위치/
$ cd site-packages/matplotlib/mpl-data
$ vi matplotlibrc
수정 전
-------------------------------------------------------------
#font.family: san-serif
-------------------------------------------------------------
수정 후
-------------------------------------------------------------
font.family: NanumGothic
-------------------------------------------------------------
홈 디렉토리 matplotlib 캐시 파일 삭제
$ rm -rf ~/.cache/matplotlib
2. 파이썬 소스 파일에서 아래 추가
-------------------------------------------------------------
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "NanumGothic"
-------------------------------------------------------------