아이패드에서 jupyter 앱인 -carnets-을 쓰다가 matplotlib 라이브러리를 쓰면 한글font가 없어서 사각형 글자로 깨져보인다. 대부분 예제가 MAC (노트북) 기준으로 작성되다 보니 아이패드의 다른 설정을 반영을 하지 못한 것이다.
ERROR MESSAGE
site-packages\IPython\core\pylabtools.py:151: UserWarning: Glyph 47928 (\N{HANGUL SYLLABLE MUN}) missing from current font
예제를 살펴보자
한글이 들어가는 부분은 제대로 보이지 않고 4각형 박스로만 표현이 된다.
# 가능한 font list 확인
import matplotlib.font_manager as fm
fontlist = [font.name for font in fm.fontManager.ttflist]
print(fontlist)
# matplotlib 사용자폰트 설정
import matplotlib.pyplot as plt
plt.rc('font', family='Apple SD Gothic Neo')
맥용으로 설정된 문구가 아이패드와는 환경이 달라 Carnets와 같은 주피터 환경에서 제대로 폰트 인식을 할 수 없다
아이패드에서는 추가로 폰트를 설치하더라도 시스템 폰트로는 인식이 되지 않아서 그런 것으로 보인다. iFont 등 폰트설치 앱을 통해 정상적으로 추가했지만 폰트리스트에 보이지 않는다면 아이패드의 기본 한글 폰트인 'Apple SD Gothic Neo'로 설정하면 정상적으로 한글폰트가 출력이 된다.
*아래는 인프런 파이썬 강좌(인프런 - 증권 데이터 수집과 분석으로 신호와 소음 찾기)의 예제에 포함된 matplotlib의 폰트를 시스템에 따라 자동으로 설정하는 문구에서 IPAD용 설정을 추가함.
def get_font_family():
"""
시스템 환경에 따른 기본 폰트명을 반환하는 함수
"""
import platform
system_name = platform.system()
# colab 사용자는 system_name이 'Linux'로 확인
if system_name == "Darwin" :
#font_family = "AppleGothic" #for MAC
font_family = "Apple SD Gothic Neo" #for IPAD
elif system_name == "Windows":
font_family = "Malgun Gothic"
else:
# Linux
# colab에서는 runtime을 <꼭> 재시작 해야합니다.
# 런타임을 재시작 하지 않고 폰트 설치를 하면 기본 설정 폰트가 로드되어 한글이 깨집니다.
!apt-get update -qq
!apt-get install fonts-nanum -qq > /dev/null
import matplotlib.font_manager as fm
fontpath = '/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf'
font = fm.FontProperties(fname=fontpath, size=9)
fm._rebuild()
font_family = "NanumBarunGothic"
return font_family
_
반응형