취미와 밥줄사이
[Matplotlib] - 한글사용 본문
Matplotlob.pyplot - 한글사용하기
- 데이터를 시각화하는 과정에서 matplot.pyplot 라이브러리가 자주 사용된다.
- 그러나 한글을 제목이나, x축, y축 라벨링을 할 때 사용하면 글자가 깨지는 문제가 발생한다.
- 그러한 상황에서는 아래의 코드를 통해서 간단히 해결할 수 있다.
※ 코랩 환경에서 사용할 때는 코드를 실행한 후 런타임을 재시작해야 적용된다.
코드는 아래와 같다.
# matplotlib.pyplot 한글사용 코드
import matplotlib as mpl
import matplotlib.pyplot as plt
%config InlineBackend.figure_format = 'retina'
!apt -qq -y install fonts-nanum
import matplotlib.font_manager as fm
fontpath = '/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf'
font = fm.FontProperties(fname=fontpath, size=9)
plt.rc('font', family='NanumBarunGothic')
mpl.font_manager._rebuild()
*Reference *
[
구글 Colab에서 한글 문제 대응하기
Python의 matplotlib의 기본 폰트가 한글을 지원하지 않아서 한글 폰트로 설정을 해주어야 합니다. 아나콘다에서는 그렇게 한글을 지원하도록 설정만 하면 문제가 없습니다. 그런데 구글의 Colab에서
pinkwink.kr
'Python > Matplotlib' 카테고리의 다른 글
[Matplotlib] - 그래프 정렬 예제 및 코드 (0) | 2021.05.07 |
---|