https://financedata.github.io/posts/matplotlib-hangul-for-ubuntu-linux.html
위 사이트를 참고하면 굉장히 상세하게 (한글) 폰트 추가 과정이 나와있다. (감사합니닷)
Jupyter notebook으로 코딩 중 위 문제를 만나게 되면, 자칫 Jupyter notebook을 켜놓고 위의 과정을 진행하게 되어, 시키시는 대로 따라했음에도 Matplotlib에서 새로 추가한 폰트를 인식하지 못하는 경우가 생긴다.
위 사이트 [글꼴 설치] 파트에서 아래 과정을 진행할 때 꼭 Jupyter Notebook이나 이미 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/*
Jupyter notebook 끄기 ! -> 위의 코드 진행 -> 다시 키기 ! :::: 마법처럼 되었다! 끝!
예시:
import matplotlib as mpl
import matplotlib as mpl
import matplotlib.font_manager as fm
set(sorted([f.name for f in fm.fontManager.ttflist]))
#---> 사용 가능한 폰트들이 뜬다!!\
#이 중 NanumBarunGothic을 사용하려면,
mpl.rcParams['font.family'] = 'NanumBarunGothic'
#폰트를 바꾸고 그래프를 그리면 -부호가 안 나오는 경우가 있는데 아래와 같이 하면 나온당.
matplotlib.rcParams['axes.unicode_minus'] = False