Programming/Others

[Colab] Matplotlib 한국어 폰트 깨짐

neopin 2022. 7. 22. 15:19

해결방안

!pip install matplotlib

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

# 런타임 재시작

 

참고

# 폰트 인스톨
# 한글폰트 사용 in colab
%matplotlib inline  

import matplotlib as mpl 
import matplotlib.pyplot as plt 
import matplotlib.font_manager as fm  


path = '/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf' 
font_name = fm.FontProperties(fname=path, size=10).get_name()
print(font_name)
plt.rc('font', family=font_name)

fm._rebuild()
mpl.rcParams['axes.unicode_minus'] = False

plt.text(0.5, 0.5, '한글되냐', size=10)