주피터 노트북(Jupyter Notebook)과 구글 코랩(Colab)에서 한글 문제 해결하기
주피터 노트북에서 한글 사용 다음 주소에 접속 : https://hangeul.naver.com/2017/nanum 윈도우용 글꼴 다운로드 : NanumFontSetup_TTF_ALL.zip 압축 해지 전체 파일 선택 후 [모든 사용자용으로 설치(A)] 클릭 사용 예
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import matplotlib.pyplot as plt from matplotlib import font_manager as fm fontpath = 'C:/Windows/Fonts/NanumBarunGothic.ttf' font = fm.FontProperties(fname=fontpath, size=9) plt.rc('font', family='NanumBarunGothic') fm._rebuild() name = ['홍길동', 'Jane', 'Tom', 'Adam'] kor = [100, 50, 100, 90] plt.bar(name, kor) plt.title("성적처리") plt.xlabel('name') plt.ylabel('score') plt.show() |
구글 코랩에서 한글 사용 반드시 [런타임] 메뉴의 [런타임 다시 시작]을 실행한 후에 다음 코드 실행 사용 예
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# Colab환경에서 matplotlib에 한글 지원 # 이 부분은 반드시 [런타임] 메뉴의 [런타임 다시 시작]을 실행한 후에 적용됨 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') fm._rebuild() name = ['홍길동', 'Jane', 'Tom', 'Adam'] kor = [100, 50, 100, 90] plt.bar(name, kor) plt.title("성적처리") plt.xlabel('name') plt.ylabel('score') plt.show() |