관리 메뉴

프로그래밍 삽질 중

구글 Colaboratory 한글(문자) 깨짐 방지 초기 설정하기 본문

과거 프로그래밍 자료들/컴퓨터설정&오류

구글 Colaboratory 한글(문자) 깨짐 방지 초기 설정하기

평부 2021. 6. 30. 01:48

※ 출처 : https://colab.research.google.com/github/nicewook/datascience_exercise/blob/master/korean_font_on_matplotlib.ipynb

 

korean_font_on_matplotlib.ipynb

Run, share, and edit Python notebooks

colab.research.google.com

※ 나눔고딕으로 진행함

 

1. 

1
2
3
!sudo apt-get install -y fonts-nanum
!sudo fc-cache -fv
!rm ~/.cache/matplotlib -rf
cs

삽입 후 상단의 [런타임] -> [런타임 초기화] 클릭

 

 2.

1
2
3
4
import matplotlib.pyplot as plt
 
plt.rc('font', family='NanumBarunGothic') #나눔고딕 설정
plt.rc("axes", unicode_minus=False) #마이너스 값 오류 시 설정
cs

3. 

1
2
3
from IPython.display import set_matplotlib_formats
 
set_matplotlib_formats("retina")
cs

 

4. 

1
2
3
4
5
6
7
8
%matplotlib inline  
 
import pandas as pd
import matplotlib as mpl  
import matplotlib.font_manager as fm 
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches #범례 그리기 위한 라이브러리
import matplotlib.lines as mlines #범례 그리기 위한 라이브러리
cs

 

적용 예시

- 파이썬으로 작업

- 공공데이터 : 전력량을 기준으로 파일 만듦(선그래프, 산점도)

- 중간에 #잘못된 출력 예시는 오류 발생했거나 적용하기 적합하지 않은 데이터를 표시한 것

 

https://colab.research.google.com/drive/1tHZl9rX5dRrb-zwxxRfXFbKQx0xdLbwK#scrollTo=DRqfWCW8VQAX

 

Google Colaboratory Notebook

Run, share, and edit Python notebooks

colab.research.google.com